Permalink
Browse files

at_exit hax to ensure that rspec's exit code wins.

- Closes #410.
  • Loading branch information...
dblock authored and dchelimsky committed Jul 30, 2011
1 parent b8bf05e commit 03a5ca5e1bc3f499cc76cf4b9c9b21c806b27013
Showing with 8 additions and 1 deletion.
  1. +1 −0 Changelog.md
  2. +6 −1 lib/rspec/core/runner.rb
  3. +1 −0 spec/rspec/core/runner_spec.rb
View
@@ -27,6 +27,7 @@ As of 2.7.0, you must explicity `require "rspec/autorun"` unless you use the
* Fix --pattern option (wasn't being recognized) (David Chelimsky)
* Only implicitly require "rspec/autorun" with the `rspec` command (David
Chelimsky)
+ * Ensure that rspec's at_exit defines the exit code (Daniel Doubrovkine)
### 2.6.4 / 2011-06-06
View
@@ -8,7 +8,12 @@ class Runner
def self.autorun
return if autorun_disabled? || installed_at_exit? || running_in_drb?
@installed_at_exit = true
- at_exit { exit(run(ARGV, $stderr, $stdout).to_i) }
+ # The order here is important, the at_exit handler must be installed before anyone else gets a chance
+ # to install their own, that way we can be assured that our exit will be last to run (at_exit stacks).
+ # see https://github.com/jnicklas/capybara/issues/178
+ exit_code = nil
+ at_exit { exit exit_code if exit_code && exit_code != 0 }
+ exit_code = run(ARGV, $stderr, $stdout).to_i
end
AT_EXIT_HOOK_BACKTRACE_LINE = "#{__FILE__}:#{__LINE__ - 2}:in `autorun'"
@@ -7,6 +7,7 @@ module RSpec::Core
RSpec::Core::Runner.stub(:installed_at_exit?).and_return(false)
RSpec::Core::Runner.stub(:running_in_drb?).and_return(false)
RSpec::Core::Runner.stub(:at_exit_hook_disabled?).and_return(false)
+ RSpec::Core::Runner.stub(:run).and_return(-1)
RSpec::Core::Runner.should_receive(:at_exit)
RSpec::Core::Runner.autorun
end

0 comments on commit 03a5ca5

Please sign in to comment.