Permalink
Browse files

Bugfix: rspec shouldn't blow up if spec files don't match "_spec.rb" …

…convention:

  People migrating to rspec may have _example.rb or _test.rb, or anything else.
  Previously metadata process would blow up if it couldn't find a _spec file
  from caller.  This (ugly) fix returns nil for file and line number if
  it can't find them.
  • Loading branch information...
1 parent 779d64c commit 06c227e89b3b7eac0e63a4412d5eb6d56745f305 @rsanheim rsanheim committed with dchelimsky Mar 19, 2010
Showing with 18 additions and 4 deletions.
  1. +9 −4 lib/rspec/core/metadata.rb
  2. +9 −0 spec/rspec/core/metadata_spec.rb
View
@@ -130,19 +130,24 @@ def described_class_from(args)
end
def file_path_from(metadata, given_file_path=nil)
- given_file_path || file_and_line_number(metadata)[0].strip
+ return given_file_path if given_file_path
+ file = file_and_line_number(metadata)[0] if file_and_line_number(metadata)
+ file.strip if file
end
def line_number_from(metadata, given_line_number=nil)
- given_line_number || file_and_line_number(metadata)[1].to_i
+ return given_line_number if given_line_number
+ line_number = file_and_line_number(metadata)[1] if file_and_line_number(metadata)
+ line_number && line_number.to_i
end
-
+
def location_from(metadata)
"#{metadata[:file_path]}:#{metadata[:line_number]}"
end
def file_and_line_number(metadata)
- candidate_entries_from_caller(metadata).first.split(':')
+ entry = candidate_entries_from_caller(metadata).first
+ entry && entry.split(":")
end
def candidate_entries_from_caller(metadata)
@@ -87,6 +87,15 @@ module Core
])
m[:example_group][:file_path].should == __FILE__
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

0 comments on commit 06c227e

Please sign in to comment.