Skip to content

Commit

Permalink
Merge pull request #2596 from timdiggins/after-teardown-in-system-specs
Browse files Browse the repository at this point in the history
run after_teardown in system specs after around (like in other specs)
  • Loading branch information
JonRowe committed May 5, 2022
1 parent 541899c commit 8f54893
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/rspec/rails/example/system_example_group.rb
Expand Up @@ -108,17 +108,19 @@ def driven_by(driver, **driver_options, &blk)
orig_stdout = $stdout
$stdout = StringIO.new
begin
if ::Rails::VERSION::STRING >= '6.0'
original_before_teardown.bind(self).call
end
original_after_teardown.bind(self).call
original_before_teardown.bind(self).call
ensure
myio = $stdout
myio.rewind
RSpec.current_example.metadata[:extra_failure_lines] = myio.readlines
$stdout = orig_stdout
end
end

around do |example|
example.run
original_after_teardown.bind(self).call
end
end
end
end
Expand Down
33 changes: 33 additions & 0 deletions spec/rspec/rails/example/system_example_group_spec.rb
Expand Up @@ -91,5 +91,38 @@ def take_screenshot
expect(example.metadata[:extra_failure_lines]).to eq(["line 1\n", "line 2\n"])
end
end

describe "hook order" do
it 'calls Capybara.reset_sessions (TestUnit after_teardown) after any after hooks' do
calls_in_order = []
allow(Capybara).to receive(:reset_sessions!) { calls_in_order << :reset_sessions! }

group = RSpec::Core::ExampleGroup.describe do
include SystemExampleGroup

before do
driven_by(:selenium)
end

after do
calls_in_order << :after_hook
end

append_after do
calls_in_order << :append_after_hook
end

around do |example|
example.run
calls_in_order << :around_hook_after_example
end
end
group.it('works') { }
group.run

expect(calls_in_order).to eq([:after_hook, :append_after_hook, :around_hook_after_example, :reset_sessions!])
end

end
end
end

0 comments on commit 8f54893

Please sign in to comment.