Skip to content

Commit

Permalink
indent all extra failure lines correctly in system tests
Browse files Browse the repository at this point in the history
If the output from Rails' system test teardown is multiple lines, we should try and render all of the lines with proper indentation.

This can happen on `rails/rails@master` now that failure screenshots can include the page HTML (rails/rails@36545), and can actually happen with v6.0.2.2 if the `method_name` ends up being a little too long.
  • Loading branch information
agrobbin committed May 18, 2020
1 parent b540020 commit b7741f2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/rspec/rails/example/system_example_group.rb
Expand Up @@ -114,7 +114,8 @@ def driven_by(driver, **driver_options, &blk)
original_after_teardown.bind(self).call
ensure
myio = $stdout
RSpec.current_example.metadata[:extra_failure_lines] = myio.string
myio.rewind
RSpec.current_example.metadata[:extra_failure_lines] = myio.readlines
$stdout = orig_stdout
end
end
Expand Down
22 changes: 22 additions & 0 deletions spec/rspec/rails/example/system_example_group_spec.rb
Expand Up @@ -58,6 +58,28 @@ module RSpec::Rails
expect(example).to have_received(:driven_by).once
end
end

describe '#after' do
it 'sets the :extra_failure_lines metadata to an array of STDOUT lines' do
group = RSpec::Core::ExampleGroup.describe do
include SystemExampleGroup

before do
driven_by(:selenium)
end

def take_screenshot
puts 'line 1'
puts 'line 2'
end
end
example = group.it('fails') { fail }

group.run

expect(example.metadata[:extra_failure_lines]).to eq(["line 1\n", "line 2\n"])
end
end
end
end
end

0 comments on commit b7741f2

Please sign in to comment.