Skip to content

Commit

Permalink
Allow passing caller trace into Metadata to support extensions
Browse files Browse the repository at this point in the history
- Closes rspec#198.
  • Loading branch information
glv authored and dchelimsky committed Oct 23, 2010
1 parent 4c5e75d commit 5d393c8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/rspec/core/metadata.rb
Expand Up @@ -32,7 +32,7 @@ def process(*args)
self[:example_group][:full_description] = full_description_from(*args)

self[:example_group][:block] = user_metadata.delete(:example_group_block)
self[:example_group][:file_path], self[:example_group][:line_number] = file_and_line_number_from(caller)
self[:example_group][:file_path], self[:example_group][:line_number] = file_and_line_number_from(user_metadata.delete(:caller) || caller)
self[:example_group][:location] = location_from(self[:example_group])

update(user_metadata)
Expand Down Expand Up @@ -68,7 +68,7 @@ def configure_for_example(description, options)
store(:description, description.to_s)
store(:full_description, "#{self[:example_group][:full_description]} #{self[:description]}")
store(:execution_result, {})
self[:file_path], self[:line_number] = file_and_line_number_from(caller)
self[:file_path], self[:line_number] = file_and_line_number_from(options.delete(:caller) || caller)
self[:location] = location_from(self)
update(options)
end
Expand Down
11 changes: 11 additions & 0 deletions spec/rspec/core/metadata_spec.rb
Expand Up @@ -13,6 +13,12 @@ module Core
end.to raise_error(/:#{key} is not allowed/)
end
end

it "uses :caller if passed as part of the user metadata" do
m = Metadata.new
m.process('group', :caller => ['example_file:42'])
m[:example_group][:location].should == 'example_file:42'
end
end

describe "description" do
Expand Down Expand Up @@ -199,6 +205,11 @@ module Core
it "extracts location from caller" do
mfe[:location].should == "#{__FILE__}:#{line_number}"
end

it "uses :caller if passed as an option" do
example_metadata = metadata.for_example('example description', {:caller => ['example_file:42']})
example_metadata[:location].should == 'example_file:42'
end

it "merges arbitrary options" do
mfe[:arbitrary].should == :options
Expand Down

0 comments on commit 5d393c8

Please sign in to comment.