Permalink
Browse files

Allow passing caller trace into Metadata to support extensions

  • Loading branch information...
1 parent f5c5838 commit 0e2b52612755b4042dd9ee5ee8248cfd5e59065f @glv glv committed with dchelimsky Oct 22, 2010
Showing with 13 additions and 2 deletions.
  1. +2 −2 lib/rspec/core/metadata.rb
  2. +11 −0 spec/rspec/core/metadata_spec.rb
@@ -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)
@@ -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
@@ -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
@@ -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

0 comments on commit 0e2b526

Please sign in to comment.