Skip to content
Browse files

Show exception classes in failures unless they come from rspec matchers

or message expectations.

- Closes #92.
  • Loading branch information...
1 parent 3e7ce82 commit 8393a463269c4b326962b56f9c7354474c3a9390 @dchelimsky dchelimsky committed Jan 1, 2011
View
3 lib/rspec/core/formatters/base_text_formatter.rb
@@ -147,7 +147,8 @@ def dump_failure(example, index)
exception = example.execution_result[:exception]
output.puts "#{short_padding}#{index.next}) #{example.full_description}"
output.puts "#{long_padding}#{red("Failure/Error:")} #{red(read_failed_line(exception, example).strip)}"
- exception.message.split("\n").each { |line| output.puts "#{long_padding}#{red(line)}" }
+ output.puts "#{long_padding}#{red(exception.class.name << ":")}" unless exception.class.name =~ /RSpec/
+ exception.message.split("\n").each { |line| output.puts "#{long_padding} #{red(line)}" }
example.example_group.ancestors.push(example.example_group).each do |group|
if group.metadata[:shared_group_name]
View
26 spec/rspec/core/formatters/base_text_formatter_spec.rb
@@ -46,6 +46,30 @@ def run_all_and_dump_failures
output.string.should =~ /(\s+)expected \"that\"\n\1 got \"this\"/m
end
+ context "with an exception class other than RSpec" do
+ it "does not show the error class" do
+ group.example("example name") { raise NameError.new('foo') }
+ run_all_and_dump_failures
+ output.string.should =~ /NameError/m
+ end
+ end
+
+ context "with a failed expectation (rspec-expectations)" do
+ it "does not show the error class" do
+ group.example("example name") { "this".should eq("that") }
+ run_all_and_dump_failures
+ output.string.should_not =~ /RSpec/m
+ end
+ end
+
+ context "with a failed message expectation (rspec-mocks)" do
+ it "does not show the error class" do
+ group.example("example name") { "this".should_receive("that") }
+ run_all_and_dump_failures
+ output.string.should_not =~ /RSpec/m
+ end
+ end
+
context 'for #share_examples_for' do
it 'outputs the name and location' do
@@ -153,7 +177,7 @@ def run_all_and_dump_failures
formatter.dump_profile
filename = __FILE__.split(File::SEPARATOR).last
- output.string.should =~ /#{filename}\:135/
+ output.string.should =~ /#{filename}\:#{__LINE__ - 21}/
end
end
end

0 comments on commit 8393a46

Please sign in to comment.
Something went wrong with that request. Please try again.