Class: Testspace::Rspec::Metadata

Inherits:
Object
  • Object
show all
Defined in:
lib/testspace/rspec/metadata.rb

Instance Method Summary collapse

Constructor Details

#initialize(rspec) ⇒ Metadata

Returns a new instance of Metadata.



7
8
9
10
# File 'lib/testspace/rspec/metadata.rb', line 7

def initialize(rspec)
  @rspec = rspec
  extend_for_description
end

Instance Method Details

#description_argObject



36
37
38
# File 'lib/testspace/rspec/metadata.rb', line 36

def description_arg
  @description_arg ||= @rspec[:description_args].first
end

#description_kindObject



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/testspace/rspec/metadata.rb', line 40

def description_kind
  @description_kind ||= begin
    case description_arg
    when ::Module
      :module
    when ::NilClass
      :anonymous
    else
      arg = description_arg.to_s
      if /^#/ =~ arg
        :instance_method
      elsif /^\./ =~ arg
        :class_method
      else
        :general
      end
    end
  end
end

#dirObject



27
28
29
30
31
32
33
34
# File 'lib/testspace/rspec/metadata.rb', line 27

def dir
  @dir ||= begin
    a = []
    a << (root? ? root_dir : parent.dir)
    a << local_dir
    a.compact.join('/')
  end
end

#extend_for_descriptionObject



60
61
62
# File 'lib/testspace/rspec/metadata.rb', line 60

def extend_for_description
  extend Extensions::Description.const_get(description_kind.to_s.pascalize, false)
end

#parentObject



12
13
14
15
16
17
# File 'lib/testspace/rspec/metadata.rb', line 12

def parent
  @parent ||= begin
    @rspec[:parent_example_group] && Metadata.new(@rspec[:parent_example_group]) ||
      @rspec.key?(:example_group) && @rspec[:example_group] && Metadata.new(@rspec[:example_group])
  end
end

#rootObject



23
24
25
# File 'lib/testspace/rspec/metadata.rb', line 23

def root
  @root ||= root? ? self : parent.root
end

#root?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/testspace/rspec/metadata.rb', line 19

def root?
  !parent
end