Permalink
Browse files

Determine example and group location without restricting to a file

pattern.

- Closes #190.
  • Loading branch information...
1 parent 03ee841 commit 9c6b6f74da382d0810ab337730828c5fd94e309b @dchelimsky dchelimsky committed Oct 14, 2010
Showing with 18 additions and 43 deletions.
  1. +2 −0 History.markdown
  2. +3 −3 lib/rspec/core/metadata.rb
  3. +13 −40 spec/rspec/core/metadata_spec.rb
View
2 History.markdown
@@ -7,6 +7,8 @@
* Bug fixes
* restore color when using spork + autotest
* Pending examples without docstrings render the correct message (Josep M. Bach)
+ * Fixed bug where a failure in a spec file ending in anything but _spec.rb would
+ fail in a confusing way.
### 2.0.0 / 2010-10-10
View
6 lib/rspec/core/metadata.rb
@@ -170,12 +170,12 @@ def location_from(metadata)
end
def file_and_line_number(metadata)
- entry = candidate_entries_from_caller(metadata).first
+ entry = first_caller_from_outside_rspec(metadata)
entry && entry.match(/(.+?):(\d+)(|:\d+)/)[1..2]
end
- def candidate_entries_from_caller(metadata)
- metadata[:caller].grep(/\_spec\.rb:/i)
+ def first_caller_from_outside_rspec(metadata)
+ metadata[:caller].detect {|l| l !~ /\/lib\/rspec\/core/}
end
end
View
53 spec/rspec/core/metadata_spec.rb
@@ -141,69 +141,42 @@ module Core
end
describe "file path" do
- it "finds the first spec file in the caller array" do
+ it "finds the first non-rspec lib file in the caller array" do
m = Metadata.new
m.process(:caller => [
- "foo",
- "#{__FILE__}:#{__LINE__}",
- "bar_spec.rb:23",
- "baz"
+ "./lib/rspec/core/foo.rb",
+ "#{__FILE__}:#{__LINE__}"
])
m[:example_group][:file_path].should == __FILE__
end
it "finds the first spec file in the caller array with drive letter" do
m = Metadata.new
- m.process(:caller => [
- "foo",
- "C:/path/file_spec.rb:#{__LINE__}",
- "bar_spec.rb:23",
- "baz"
- ])
+ m.process(:caller => [ "C:/path/file_spec.rb:#{__LINE__}" ])
m[:example_group][:file_path].should == "C:/path/file_spec.rb"
end
-
- it "is nil if there are no spec files found", :full_backtrace => true do
- m = Metadata.new
- m.process(:caller => [
- "foo",
- "metadata_example.rb:#{__LINE__}",
- "baz"
- ])
- m[:example_group][:file_path].should be_nil
- end
end
describe "line number" do
- it "finds the line number with the first spec file in the backtrace" do
+ it "finds the line number with the first non-rspec lib file in the backtrace" do
m = Metadata.new
m.process(:caller => [
- "foo",
+ "./lib/rspec/core/foo.rb",
"#{__FILE__}:#{__LINE__}",
- "bar_spec.rb:23",
- "baz"
])
- m[:example_group][:line_number].should == __LINE__ - 4
+ m[:example_group][:line_number].should == __LINE__ - 2
end
+
it "finds the line number with the first spec file with drive letter" do
m = Metadata.new
- m.process(:caller => [
- "foo",
- "C:/path/to/file_spec.rb:#{__LINE__}",
- "bar_spec.rb:23",
- "baz"
- ])
- m[:example_group][:line_number].should == __LINE__ - 4
+ m.process(:caller => [ "C:/path/to/file_spec.rb:#{__LINE__}" ])
+ m[:example_group][:line_number].should == __LINE__ - 1
end
+
it "uses the number after the first : for ruby 1.9" do
m = Metadata.new
- m.process(:caller => [
- "foo",
- "#{__FILE__}:#{__LINE__}:999",
- "bar_spec.rb:23",
- "baz"
- ])
- m[:example_group][:line_number].should == __LINE__ - 4
+ m.process(:caller => [ "#{__FILE__}:#{__LINE__}:999" ])
+ m[:example_group][:line_number].should == __LINE__ - 1
end
end

0 comments on commit 9c6b6f7

Please sign in to comment.