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



27
28
29
# File 'lib/testspace/rspec/metadata.rb', line 27

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

#description_kindObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/testspace/rspec/metadata.rb', line 31

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



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

def dir
  @dir ||= parent ? "#{parent.dir}/#{local_dir}" : "#{root_dir}/#{local_dir}"
end

#extend_for_descriptionObject



51
52
53
# File 'lib/testspace/rspec/metadata.rb', line 51

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] && .new(@rspec[:parent_example_group]) ||
      @rspec.key?(:example_group) && @rspec[:example_group] && .new(@rspec[:example_group])
  end
end

#rootObject



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

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