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

Commit a1936ff

Browse files
committed
Make ExceptionPresenter#fully_formatted support a nil arg.
This is necessary for cases where the error is not part of a numbered sequence (such as a :suite hook error).
1 parent 910eb7f commit a1936ff

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

lib/rspec/core/formatters/exception_presenter.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,8 @@ def encoded_string(string)
122122
end
123123

124124
def indent_lines(lines, failure_number)
125-
alignment_basis = "#{' ' * @indentation}#{failure_number}) "
125+
alignment_basis = ' ' * @indentation
126+
alignment_basis << "#{failure_number}) " if failure_number
126127
indentation = ' ' * alignment_basis.length
127128

128129
lines.each_with_index.map do |line, index|

spec/rspec/core/formatters/exception_presenter_spec.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,18 @@ module RSpec::Core
5151
EOS
5252
end
5353

54+
it "prints no identifier when no number argument is given" do
55+
expect(presenter.fully_formatted(nil)).to eq(<<-EOS.gsub(/^ +\|/, ''))
56+
|
57+
| Example
58+
| Failure/Error: # The failure happened here!#{ encoding_check }
59+
|
60+
| Boom
61+
| Bam
62+
| # ./spec/rspec/core/formatters/exception_presenter_spec.rb:#{line_num}
63+
EOS
64+
end
65+
5466
it "allows the caller to specify additional indentation" do
5567
the_presenter = Formatters::ExceptionPresenter.new(exception, example, :indentation => 4)
5668

0 commit comments

Comments
 (0)