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

Commit

Permalink
Merge pull request #3006 from rspec/fix-additional-whitespace-around-…
Browse files Browse the repository at this point in the history
…extra-failure-lines

Skip adding whitespace around extrafailure lines when already present
  • Loading branch information
JonRowe committed Feb 3, 2023
1 parent e9363ce commit 5d9a877
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
5 changes: 5 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
### Development
[Full Changelog](http://github.com/rspec/rspec-core/compare/v3.12.0...3-12-maintenance)

Bug fixes:

* Prevent multiple calls to `extra_failure_lines` from adding additional whitespace
around them when the lines already contain whitespace. (Jon Rowe, #3006)

### 3.12.0 / 2022-10-26
[Full Changelog](http://github.com/rspec/rspec-core/compare/v3.11.0...v3.12.0)

Expand Down
4 changes: 2 additions & 2 deletions lib/rspec/core/formatters/exception_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,8 @@ def extra_failure_lines
@extra_failure_lines ||= begin
lines = Array(example.metadata[:extra_failure_lines])
unless lines.empty?
lines.unshift('')
lines.push('')
lines.unshift('') unless lines.first == ''
lines.push('') unless lines.last == ''
end
lines
end
Expand Down
19 changes: 19 additions & 0 deletions spec/rspec/core/formatters/exception_presenter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,25 @@ def to_s
EOS
end

it "wont add extra blank lines around extra failure lines when lines are already padded" do
extra_example = example.clone
failure_line = 'http://www.example.com/job_details/123'
extra_example.metadata[:extra_failure_lines] = ['', failure_line, '']
the_presenter = Formatters::ExceptionPresenter.new(exception, extra_example, :indentation => 4)
expect(the_presenter.fully_formatted(1)).to eq(<<-EOS.gsub(/^ +\|/, ''))
|
| 1) Example
| Failure/Error: # The failure happened here!#{ encoding_check }
|
| Boom
| Bam
|
| #{failure_line}
|
| # ./spec/rspec/core/formatters/exception_presenter_spec.rb:#{line_num}
EOS
end

describe 'line format' do
let(:exception) do
begin
Expand Down

0 comments on commit 5d9a877

Please sign in to comment.