module RSpec::Core::Metadata::MetadataHash

@private

Public Instance Methods

[](key) click to toggle source

@private Supports lazy evaluation of some values. Extended by ExampleMetadataHash and GroupMetadataHash, which get mixed in to Metadata for ExampleGroups and Examples (respectively).

Calls superclass method
# File lib/rspec/core/metadata.rb, line 43
def [](key)
  return super if has_key?(key)
  case key
  when :location
    store(:location, location)
  when :file_path, :line_number
    file_path, line_number = file_and_line_number
    store(:file_path, file_path)
    store(:line_number, line_number)
    super
  when :execution_result
    store(:execution_result, {})
  when :describes, :described_class
    klass = described_class
    store(:described_class, klass)
    # TODO (2011-11-07 DC) deprecate :describes as a key
    store(:describes, klass)
  when :full_description
    store(:full_description, full_description)
  when :description
    store(:description, build_description_from(*self[:description_args]))
  else
    super
  end
end

Private Instance Methods

build_description_from(*parts) click to toggle source
# File lib/rspec/core/metadata.rb, line 84
def build_description_from(*parts)
  parts.map {|p| p.to_s}.inject do |desc, p|
    p =~ /^(#|::|\.)/ ? "#{desc}#{p}" : "#{desc} #{p}"
  end || ""
end
file_and_line_number() click to toggle source
# File lib/rspec/core/metadata.rb, line 75
def file_and_line_number
  first_caller_from_outside_rspec =~ /(.+?):(\d+)(|:\d+)/
  return [Metadata::relative_path($1), $2.to_i]
end
first_caller_from_outside_rspec() click to toggle source
# File lib/rspec/core/metadata.rb, line 80
def first_caller_from_outside_rspec
  self[:caller].detect {|l| l !~ /\/lib\/rspec\/core/}
end
location() click to toggle source
# File lib/rspec/core/metadata.rb, line 71
def location
  "#{self[:file_path]}:#{self[:line_number]}"
end