Permalink
Browse files

Render exceptions with multi-line messages like MRI

Fixes a test failure in rspec-mocks.
  • Loading branch information...
1 parent fd8fd59 commit 860097188c8682ae3199a0f905236189b1d8a4e9 @jfirebaugh jfirebaugh committed Apr 30, 2012
Showing with 17 additions and 1 deletion.
  1. +7 −1 kernel/common/exception.rb
  2. +10 −0 spec/core/exception/render_spec.rb
@@ -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:"
@@ -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.