Skip to content
This repository was archived by the owner on Nov 30, 2024. It is now read-only.

Commit 90a15b2

Browse files
pirjJonRowe
authored andcommitted
Merge pull request #2903 from zinovyev/patch-1
Do not fail if an Exception has no backtrace
1 parent e281de2 commit 90a15b2

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed

Changelog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ Enhancements:
4646
Bug fixes:
4747

4848
* Ensure bisect communication uses consistent encoding. (Mike Jarema, #2852)
49+
* Fix exception presenter when the root cause exception has nil backtrace.
50+
(Zinovyev Ivan, #2903)
4951

5052
### 3.10.1 / 2020-12-27
5153
[Full Changelog](http://github.com/rspec/rspec-core/compare/v3.10.0...v3.10.1)

lib/rspec/core/formatters/exception_presenter.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def formatted_cause(exception)
5353
cause << " #{line}"
5454
end
5555

56-
unless last_cause.backtrace.empty?
56+
unless last_cause.backtrace.nil? || last_cause.backtrace.empty?
5757
cause << (" #{backtrace_formatter.format_backtrace(last_cause.backtrace, example.metadata).first}")
5858
end
5959
end

spec/rspec/core/formatters/exception_presenter_spec.rb

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,42 @@ def initialize(message, backtrace = [], cause = nil)
199199
EOS
200200
end
201201

202+
context "when the first exception doesn't have a backgrace" do
203+
let(:first_exception) { FakeException.new("Real\nculprit", backtrace) }
204+
205+
shared_examples 'expected result for the case when there is no backtrace' do
206+
it 'wont fail for the exception with a nil backtrace' do
207+
the_presenter = Formatters::ExceptionPresenter.new(the_exception, example)
208+
209+
expect(the_presenter.fully_formatted(1)).to eq(<<-EOS.gsub(/^ +\|/, ''))
210+
|
211+
| 1) Example
212+
| Failure/Error: # The failure happened here!#{ encoding_check }
213+
|
214+
| Boom
215+
| Bam
216+
| # ./spec/rspec/core/formatters/exception_presenter_spec.rb:#{line_num}
217+
| # ------------------
218+
| # --- Caused by: ---
219+
| # Real
220+
| # culprit
221+
EOS
222+
end
223+
end
224+
225+
context 'when backtrace is []' do
226+
let(:backtrace) { [] }
227+
228+
it_behaves_like 'expected result for the case when there is no backtrace'
229+
end
230+
231+
context 'when backtrace is nil' do
232+
let(:backtrace) { nil }
233+
234+
it_behaves_like 'expected result for the case when there is no backtrace'
235+
end
236+
end
237+
202238
it 'wont produce a stack error when cause is the exception itself' do
203239
allow(the_exception).to receive(:cause) { the_exception }
204240
the_presenter = Formatters::ExceptionPresenter.new(the_exception, example)

0 commit comments

Comments
 (0)