Skip to content

Commit

Permalink
Render exceptions with multi-line messages like MRI
Browse files Browse the repository at this point in the history
Fixes a test failure in rspec-mocks.
  • Loading branch information
jfirebaugh committed May 1, 2012
1 parent fd8fd59 commit 8600971
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
8 changes: 7 additions & 1 deletion kernel/common/exception.rb
Expand Up @@ -50,8 +50,14 @@ def awesome_backtrace
end

def render(header="An exception occurred", io=STDERR, color=true)
message_lines = message.to_s.split("\n")

io.puts header
io.puts " #{message} (#{self.class})"
io.puts " #{message_lines.shift} (#{self.class})"

message_lines.each do |line|
io.puts " #{line}"
end

if @custom_backtrace
io.puts "\nUser defined backtrace:"
Expand Down
10 changes: 10 additions & 0 deletions spec/core/exception/render_spec.rb
@@ -0,0 +1,10 @@
require File.expand_path('../../../spec_helper', __FILE__)
require 'stringio'

describe "Exception#render" do
it "renders a multi-line message with the class name included in the first line" do
io = StringIO.new
Exception.new("line1\nline2\nline3").render("", io)
io.string.should include("line1 (Exception)\n")
end
end

0 comments on commit 8600971

Please sign in to comment.