@private
@private Supports lazy evaluation of some values. Extended by ExampleMetadataHash and GroupMetadataHash, which get mixed in to Metadata for ExampleGroups and Examples (respectively).
# File lib/rspec/core/metadata.rb, line 45 def [](key) store_computed(key) unless has_key?(key) super end
# File lib/rspec/core/metadata.rb, line 50 def fetch(key, *args) store_computed(key) unless has_key?(key) super end
# File lib/rspec/core/metadata.rb, line 97 def build_description_from(first_part = '', *parts) description, _ = parts.inject([first_part.to_s, first_part]) do |(desc, last_part), this_part| this_part = this_part.to_s this_part = (' ' + this_part) unless method_description_after_module?(last_part, this_part) [(desc + this_part), this_part] end description end
# File lib/rspec/core/metadata.rb, line 83 def file_and_line_number first_caller_from_outside_rspec =~ /(.+?):(\d+)(|:\d+)/ return [Metadata::relative_path($1), $2.to_i] end
# File lib/rspec/core/metadata.rb, line 88 def first_caller_from_outside_rspec self[:caller].detect {|l| l !~ /\/lib\/rspec\/core/} end
# File lib/rspec/core/metadata.rb, line 79 def location "#{self[:file_path]}:#{self[:line_number]}" end
# File lib/rspec/core/metadata.rb, line 92 def method_description_after_module?(parent_part, child_part) return false unless parent_part.is_a?(Module) child_part =~ /^(#|::|\.)/ end
# File lib/rspec/core/metadata.rb, line 57 def store_computed(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) 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])) end end