Created
September 12, 2012 04:06
-
-
Save japgolly/3704227 to your computer and use it in GitHub Desktop.
Issue with RSpec and at_exit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def dynamic_fixture_root | |
$gu_dynamic_fixture_root || DYNAMIC_FIXTURE_ROOT_LOCK.synchronize { | |
$gu_dynamic_fixture_root ||= ( | |
at_exit { | |
FileUtils.remove_entry_secure $gu_dynamic_fixture_root if $gu_dynamic_fixture_root | |
$gu_dynamic_fixtures= $gu_dynamic_fixture_root= nil | |
} | |
Dir.mktmpdir | |
) | |
} | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This file is available in: https://raw.github.com/japgolly/golly-utils | |
module Kernel | |
# Alternate implementation of `at_exit` that preserves the exit status (unless you call `exit` yourself and an error | |
# is raised). | |
# | |
# The initial driver for this was that using `at_exit` to clean up global resources in RSpec tests, RSpec's exit | |
# status would be lost which means CI processes and such were unable to tell whether there were test failures. | |
# | |
# @return [Proc] Whatever `at_exit` returns. | |
def at_exit_preserving_exit_status(&block) | |
at_exit { | |
status= $!.is_a?(::SystemExit) ? $!.status : nil | |
block.() | |
exit status if status | |
} | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment