Class: RSpec::Core::Metadata

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

Overview

Each ExampleGroup class and Example instance owns an instance of Metadata, which is Hash extended to support lazy evaluation of values associated with keys that may or may not be used by any example or group.

In addition to metadata that is used internally, this also stores user-supplied metadata, e.g.

describe Something, :type => :ui do
  it "does something", :slow => true do
    # ...
  end
end

:type => :ui is stored in the Metadata owned by the example group, and :slow => true is stored in the Metadata owned by the example. These can then be used to select which examples are run using the --tag option on the command line, or several methods on Configuration used to filter a run (e.g. filter_run_including, filter_run_excluding, etc).

See Also:

Defined Under Namespace

Modules: ExampleMetadataHash, GroupMetadataHash

Constant Summary

RESERVED_KEYS =
[
  :description,
  :example_group,
  :execution_result,
  :file_path,
  :full_description,
  :line_number,
  :location
]

Class Attribute Summary (collapse)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Metadata) initialize(parent_group_metadata = nil) {|_self| ... }

A new instance of Metadata

Yields:

  • (_self)

Yield Parameters:

215
216
217
218
219
220
221
222
223
224
# File 'lib/rspec/core/metadata.rb', line 215
def initialize(=nil)
  if 
    update()
    store(:example_group, {:example_group => [:example_group].extend(GroupMetadataHash)}.extend(GroupMetadataHash))
  else
    store(:example_group, {}.extend(GroupMetadataHash))
  end
  yield self if block_given?
end

Class Attribute Details

+ (Object) line_number_filter_deprecation_issued

Returns the value of attribute linenumberfilterdeprecationissued

29
30
31
# File 'lib/rspec/core/metadata.rb', line 29
def line_number_filter_deprecation_issued
  @line_number_filter_deprecation_issued
end

Class Method Details

+ (Object) relative_path(line)

32
33
34
35
36
37
38
39
# File 'lib/rspec/core/metadata.rb', line 32
def self.relative_path(line)
  line = line.sub(File.expand_path("."), ".")
  line = line.sub(/\A([^:]+:\d+)$/, '\\1')
  return nil if line == '-e:1'
  line
rescue SecurityError
  nil
end