Skip to content

Commit b7741f2

Browse files
committed
indent all extra failure lines correctly in system tests
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.
1 parent b540020 commit b7741f2

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

lib/rspec/rails/example/system_example_group.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@ def driven_by(driver, **driver_options, &blk)
114114
original_after_teardown.bind(self).call
115115
ensure
116116
myio = $stdout
117-
RSpec.current_example.metadata[:extra_failure_lines] = myio.string
117+
myio.rewind
118+
RSpec.current_example.metadata[:extra_failure_lines] = myio.readlines
118119
$stdout = orig_stdout
119120
end
120121
end

spec/rspec/rails/example/system_example_group_spec.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,28 @@ module RSpec::Rails
5858
expect(example).to have_received(:driven_by).once
5959
end
6060
end
61+
62+
describe '#after' do
63+
it 'sets the :extra_failure_lines metadata to an array of STDOUT lines' do
64+
group = RSpec::Core::ExampleGroup.describe do
65+
include SystemExampleGroup
66+
67+
before do
68+
driven_by(:selenium)
69+
end
70+
71+
def take_screenshot
72+
puts 'line 1'
73+
puts 'line 2'
74+
end
75+
end
76+
example = group.it('fails') { fail }
77+
78+
group.run
79+
80+
expect(example.metadata[:extra_failure_lines]).to eq(["line 1\n", "line 2\n"])
81+
end
82+
end
6183
end
6284
end
6385
end

0 commit comments

Comments
 (0)