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

Add scenario explaining example failures do not affect hooks #2715

Merged
merged 1 commit into from Apr 4, 2020
Merged
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
26 changes: 25 additions & 1 deletion features/hooks/before_and_after_hooks.feature
Expand Up @@ -25,7 +25,8 @@ Feature: `before` and `after` hooks
A bare `before` or `after` hook defaults to the `:example` scope.

`before` and `after` hooks can be defined directly in the example groups they
should run in, or in a global `RSpec.configure` block.
should run in, or in a global `RSpec.configure` block. Note that the status of
the example does not affect the hooks.

**WARNING:** Setting instance variables are not supported in `before(:suite)`.

Expand Down Expand Up @@ -189,6 +190,29 @@ Feature: `before` and `after` hooks
# ./after_context_spec.rb:3
"""

Scenario: A failure in an example does not affect hooks
Given a file named "failure_in_example_spec.rb" with:
"""ruby
RSpec.describe "a failing example does not affect hooks" do
before(:context) { puts "before context runs" }
before(:example) { puts "before example runs" }
after(:example) { puts "after example runs" }
after(:context) { puts "after context runs" }

it "fails the example but runs the hooks" do
raise "An Error"
end
end
"""
When I run `rspec failure_in_example_spec.rb`
Then it should fail with:
"""
before context runs
before example runs
after example runs
Fafter context runs
"""

Scenario: Define `before` and `after` blocks in configuration
Given a file named "befores_in_configuration_spec.rb" with:
"""ruby
Expand Down