Skip to content

Fix NoMethodError when an exception has no message. #308

Closed
wants to merge 3 commits into from
View
2 lib/rspec/core/formatters/base_text_formatter.rb
@@ -148,7 +148,7 @@ def dump_failure(example, index)
output.puts "#{short_padding}#{index.next}) #{example.full_description}"
output.puts "#{long_padding}#{red("Failure/Error:")} #{red(read_failed_line(exception, example).strip)}"
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)}" }
+ exception.message.split("\n").each { |line| output.puts "#{long_padding} #{red(line)}" } if exception.message
example.example_group.ancestors.push(example.example_group).each do |group|
if group.metadata[:shared_group_name]
View
9 spec/rspec/core/formatters/base_text_formatter_spec.rb
@@ -46,6 +46,15 @@ def run_all_and_dump_failures
output.string.should =~ /(\s+)expected \"that\"\n\1 got \"this\"/m
end
+ context "with an exception without a message" do
+ it "does not throw NoMethodError" do
+ exception_without_message = Exception.new()
+ exception_without_message.stub(:message){nil}
+ group.example("example name") { raise exception_without_message }
+ expect { run_all_and_dump_failures }.to_not raise_error(NoMethodError)
+ end
+ 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') }
Something went wrong with that request. Please try again.