Class/Module Index [+]

Quicksearch

RSpec::Core::Metadata

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 Example#metadata @see ExampleGroup.metadata @see FilterManager @see Configuration#filter_run_including @see Configuration#filter_run_excluding

Constants

RESERVED_KEYS

@private

Public Class Methods

backtrace_from(block) click to toggle source

@private

# File lib/rspec/core/metadata.rb, line 62
def self.backtrace_from(block)
  return caller unless block.respond_to?(:source_location)
  [block.source_location.join(':')]
end
build_hash_from(args, warn_about_example_group_filtering=false) click to toggle source

@private Used internally to build a hash from an args array. Symbols are converted into hash keys with a value of `true`. This is done to support simple tagging using a symbol, rather than needing to do `:symbol => true`.

# File lib/rspec/core/metadata.rb, line 46
def self.build_hash_from(args, warn_about_example_group_filtering=false)
  hash = args.last.is_a?(Hash) ? args.pop : {}

  while args.last.is_a?(Symbol)
    hash[args.pop] = true
  end

  if warn_about_example_group_filtering && hash.key?(:example_group)
    RSpec.deprecate("Filtering by an `:example_group` subhash",
                    :replacement => "the subhash to filter directly")
  end

  hash
end
relative_path(line) click to toggle source

@api private

@param line [String] current code line @return [String] relative path to line

# 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

[Validate]

Generated with the Darkfish Rdoc Generator 2.