Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix NoMethodError when an exception has no message. #308

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/rspec/core/formatters/base_text_formatter.rb
Expand Up @@ -148,7 +148,7 @@ def dump_failure(example, index)
output.puts "#{short_padding}#{index.next}) #{example.full_description}" 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("Failure/Error:")} #{red(read_failed_line(exception, example).strip)}"
output.puts "#{long_padding}#{red(exception.class.name << ":")}" unless exception.class.name =~ /RSpec/ 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| example.example_group.ancestors.push(example.example_group).each do |group|
if group.metadata[:shared_group_name] if group.metadata[:shared_group_name]
Expand Down
9 changes: 9 additions & 0 deletions spec/rspec/core/formatters/base_text_formatter_spec.rb
Expand Up @@ -46,6 +46,15 @@ def run_all_and_dump_failures
output.string.should =~ /(\s+)expected \"that\"\n\1 got \"this\"/m output.string.should =~ /(\s+)expected \"that\"\n\1 got \"this\"/m
end 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 context "with an exception class other than RSpec" do
it "does not show the error class" do it "does not show the error class" do
group.example("example name") { raise NameError.new('foo') } group.example("example name") { raise NameError.new('foo') }
Expand Down