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

Set the exit status to non-zero for after(:context) errors. #2320

Merged
merged 1 commit into from
Sep 2, 2016
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ Bug Fixes:
conflicting keys if the value in the host group was inherited from
a parent group instead of being specified at that level.
(Myron Marston, #2307)
* Handle errors in `:suite` hooks and provided the same nicely formatted
* Handle errors in `:suite` hooks and provide the same nicely formatted
output as errors that happen in examples. (Myron Marston, #2316)
* Set the exit status to non-zero when an error occurs in an
`after(:context)` hook. (Myron Marston, #2320)

### 3.5.2 / 2016-07-28
[Full Changelog](http://github.com/rspec/rspec-core/compare/v3.5.1...v3.5.2)
Expand Down
9 changes: 6 additions & 3 deletions features/hooks/before_and_after_hooks.feature
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,14 @@ Feature: `before` and `after` hooks
end
"""
When I run `rspec after_context_spec.rb`
Then the examples should all pass
And the output should contain:
Then it should fail with:
"""
An error occurred in an `after(:context)` hook.
StandardError: Boom!
Failure/Error: raise StandardError.new("Boom!")

StandardError:
Boom!
# ./after_context_spec.rb:3
"""

Scenario: Define `before` and `after` blocks in configuration
Expand Down
9 changes: 1 addition & 8 deletions lib/rspec/core/hooks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -365,14 +365,7 @@ class AfterContextHook < Hook
def run(example)
example.instance_exec(example, &block)
rescue Support::AllExceptionsExceptOnesWeMustNotRescue => e
# TODO: Come up with a better solution for this.
RSpec.configuration.reporter.message <<-EOS

An error occurred in an `after(:context)` hook.
#{e.class}: #{e.message}
occurred at #{e.backtrace.first}

EOS
RSpec.configuration.reporter.notify_non_example_exception(e, "An error occurred in an `after(:context)` hook.")
end
end

Expand Down
6 changes: 6 additions & 0 deletions spec/rspec/core/example_group_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1014,6 +1014,12 @@ def define_and_run_group(define_outer_example = false)
self.group.run
expect(hooks_run).to eq [:two,:one]
end

it "sets `world.non_example_failure` so the exit status will be non-zero" do
expect {
self.group.run
}.to change { RSpec.world.non_example_failure }.from(a_falsey_value).to(true)
end
end
end

Expand Down