Skip to content

Commit 067f4bc

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 067f4bc

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-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: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,31 @@ 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 set_exception(*) # rubocop:disable Naming/AccessorMethodName
72+
end
73+
74+
def take_screenshot
75+
puts 'line 1'
76+
puts 'line 2'
77+
end
78+
end
79+
example = group.it('fails') { fail }
80+
81+
group.run
82+
83+
expect(example.metadata[:extra_failure_lines]).to eq(["line 1\n", "line 2\n"])
84+
end
85+
end
6186
end
6287
end
6388
end

0 commit comments

Comments
 (0)