|
15 | 15 | it "supports :highlight option and adds escape sequences to highlight some strings" do |
16 | 16 | e = RuntimeError.new("Some runtime error") |
17 | 17 |
|
18 | | - full_message = e.full_message(highlight: true, order: :bottom) |
19 | | - full_message.should include "\e[1mTraceback\e[m (most recent call last)" |
20 | | - full_message.should include "\e[1mSome runtime error (\e[1;4mRuntimeError\e[m\e[1m)" |
| 18 | + full_message = e.full_message(highlight: true, order: :top).lines |
| 19 | + full_message[0].should.end_with? "\e[1mSome runtime error (\e[1;4mRuntimeError\e[m\e[1m)\e[m\n" |
21 | 20 |
|
22 | | - full_message = e.full_message(highlight: false, order: :bottom) |
23 | | - full_message.should include "Traceback (most recent call last)" |
24 | | - full_message.should include "Some runtime error (RuntimeError)" |
| 21 | + full_message = e.full_message(highlight: true, order: :bottom).lines |
| 22 | + full_message[0].should == "\e[1mTraceback\e[m (most recent call last):\n" |
| 23 | + full_message[-1].should.end_with? "\e[1mSome runtime error (\e[1;4mRuntimeError\e[m\e[1m)\e[m\n" |
| 24 | + |
| 25 | + full_message = e.full_message(highlight: false, order: :top).lines |
| 26 | + full_message[0].should.end_with? "Some runtime error (RuntimeError)\n" |
| 27 | + |
| 28 | + full_message = e.full_message(highlight: false, order: :bottom).lines |
| 29 | + full_message[0].should == "Traceback (most recent call last):\n" |
| 30 | + full_message[-1].should.end_with? "Some runtime error (RuntimeError)\n" |
25 | 31 | end |
26 | 32 |
|
27 | 33 | it "supports :order option and places the error message and the backtrace at the top or the bottom" do |
|
35 | 41 | it "shows the caller if the exception has no backtrace" do |
36 | 42 | e = RuntimeError.new("Some runtime error") |
37 | 43 | e.backtrace.should == nil |
38 | | - full_message = e.full_message(highlight: false, order: :top) |
39 | | - full_message.should include("#{__FILE__}:#{__LINE__-1}:in `") |
40 | | - full_message.should include("': Some runtime error (RuntimeError)\n") |
| 44 | + full_message = e.full_message(highlight: false, order: :top).lines |
| 45 | + full_message[0].should.start_with?("#{__FILE__}:#{__LINE__-1}:in `") |
| 46 | + full_message[0].should.end_with?("': Some runtime error (RuntimeError)\n") |
41 | 47 | end |
42 | 48 |
|
43 | 49 | it "shows the exception class at the end of the first line of the message when the message contains multiple lines" do |
44 | 50 | begin |
45 | 51 | line = __LINE__; raise "first line\nsecond line" |
46 | 52 | rescue => e |
47 | 53 | full_message = e.full_message(highlight: false, order: :top).lines |
48 | | - full_message[0].should include("#{__FILE__}:#{line}:in `") |
49 | | - full_message[0].should include(": first line (RuntimeError)\n") |
| 54 | + full_message[0].should.start_with?("#{__FILE__}:#{line}:in `") |
| 55 | + full_message[0].should.end_with?(": first line (RuntimeError)\n") |
50 | 56 | full_message[1].should == "second line\n" |
51 | 57 | end |
52 | 58 | end |
53 | 59 |
|
| 60 | + it "highlights the entire message when the message contains multiple lines" do |
| 61 | + begin |
| 62 | + line = __LINE__; raise "first line\nsecond line\nthird line" |
| 63 | + rescue => e |
| 64 | + full_message = e.full_message(highlight: true, order: :top).lines |
| 65 | + full_message[0].should.start_with?("#{__FILE__}:#{line}:in `") |
| 66 | + full_message[0].should.end_with?(": \e[1mfirst line (\e[1;4mRuntimeError\e[m\e[1m)\e[m\n") |
| 67 | + full_message[1].should == "\e[1msecond line\e[m\n" |
| 68 | + full_message[2].should == "\e[1mthird line\e[m\n" |
| 69 | + end |
| 70 | + end |
| 71 | + |
54 | 72 | it "contains cause of exception" do |
55 | 73 | begin |
56 | 74 | begin |
|
0 commit comments