Skip to content
This repository was archived by the owner on Nov 30, 2024. It is now read-only.

Commit 88b7b4c

Browse files
authored
Merge pull request #2320 from rspec/myron/fix-after-context-failures
Set the exit status to non-zero for `after(:context)` errors.
2 parents d7ff6b3 + c6a13d4 commit 88b7b4c

File tree

4 files changed

+16
-12
lines changed

4 files changed

+16
-12
lines changed

Changelog.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@ Bug Fixes:
1919
conflicting keys if the value in the host group was inherited from
2020
a parent group instead of being specified at that level.
2121
(Myron Marston, #2307)
22-
* Handle errors in `:suite` hooks and provided the same nicely formatted
22+
* Handle errors in `:suite` hooks and provide the same nicely formatted
2323
output as errors that happen in examples. (Myron Marston, #2316)
24+
* Set the exit status to non-zero when an error occurs in an
25+
`after(:context)` hook. (Myron Marston, #2320)
2426

2527
### 3.5.2 / 2016-07-28
2628
[Full Changelog](http://github.com/rspec/rspec-core/compare/v3.5.1...v3.5.2)

features/hooks/before_and_after_hooks.feature

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,11 +174,14 @@ Feature: `before` and `after` hooks
174174
end
175175
"""
176176
When I run `rspec after_context_spec.rb`
177-
Then the examples should all pass
178-
And the output should contain:
177+
Then it should fail with:
179178
"""
180179
An error occurred in an `after(:context)` hook.
181-
StandardError: Boom!
180+
Failure/Error: raise StandardError.new("Boom!")
181+
182+
StandardError:
183+
Boom!
184+
# ./after_context_spec.rb:3
182185
"""
183186

184187
Scenario: Define `before` and `after` blocks in configuration

lib/rspec/core/hooks.rb

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -365,14 +365,7 @@ class AfterContextHook < Hook
365365
def run(example)
366366
example.instance_exec(example, &block)
367367
rescue Support::AllExceptionsExceptOnesWeMustNotRescue => e
368-
# TODO: Come up with a better solution for this.
369-
RSpec.configuration.reporter.message <<-EOS
370-
371-
An error occurred in an `after(:context)` hook.
372-
#{e.class}: #{e.message}
373-
occurred at #{e.backtrace.first}
374-
375-
EOS
368+
RSpec.configuration.reporter.notify_non_example_exception(e, "An error occurred in an `after(:context)` hook.")
376369
end
377370
end
378371

spec/rspec/core/example_group_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,6 +1014,12 @@ def define_and_run_group(define_outer_example = false)
10141014
self.group.run
10151015
expect(hooks_run).to eq [:two,:one]
10161016
end
1017+
1018+
it "sets `world.non_example_failure` so the exit status will be non-zero" do
1019+
expect {
1020+
self.group.run
1021+
}.to change { RSpec.world.non_example_failure }.from(a_falsey_value).to(true)
1022+
end
10171023
end
10181024
end
10191025

0 commit comments

Comments
 (0)