Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

run after_teardown in system specs after around (like in other specs) #2596

Merged
merged 3 commits into from May 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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