Module: RSpec::Core::Metadata::LocationKeys

Defined in:
lib/rspec/core/metadata.rb

Instance Method Summary collapse

Instance Method Details

#[](key) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/rspec/core/metadata.rb', line 6

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)
    self[key]
  else
    super
  end
end

#file_and_line_numberObject



25
26
27
28
# File 'lib/rspec/core/metadata.rb', line 25

def file_and_line_number
  first_caller_from_outside_rspec =~ /(.+?):(\d+)(|:\d+)/
  return [$1, $2.to_i]
end

#first_caller_from_outside_rspecObject



30
31
32
# File 'lib/rspec/core/metadata.rb', line 30

def first_caller_from_outside_rspec
  self[:caller].detect {|l| l !~ /\/lib\/rspec\/core/}
end

#locationObject



21
22
23
# File 'lib/rspec/core/metadata.rb', line 21

def location
  "#{self[:file_path]}:#{self[:line_number]}"
end