Skip to content

Instantly share code, notes, and snippets.

@mhenrixon
Created August 16, 2012 08:35
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mhenrixon/3368432 to your computer and use it in GitHub Desktop.
Save mhenrixon/3368432 to your computer and use it in GitHub Desktop.
Monkey patch to make ruby exit codes work with continuous integration
# Monkey Patch ruby because of a bug introduced in ruby versions greater than 1.9.2
# For some reason the exit code is all wrong in later version of ruby and even though
# the issue was closed as sorted it's still broken in ruby version 1.9.3-p194.
# (see http://redmine.ruby-lang.org/issues/5218 for more information)
# Put this in spec_helper.rb or test_helper.rb so that it only affects specs and the CI server.
if defined?(RUBY_ENGINE) && RUBY_ENGINE == "ruby" && RUBY_VERSION >= "1.9"
module Kernel
alias :__at_exit :at_exit
def at_exit(&block)
__at_exit do
exit_status = $!.status if $!.is_a?(SystemExit)
block.call
exit exit_status if exit_status
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment