Skip to content

Instantly share code, notes, and snippets.

@japgolly
Created September 12, 2012 04:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save japgolly/3704227 to your computer and use it in GitHub Desktop.
Save japgolly/3704227 to your computer and use it in GitHub Desktop.
Issue with RSpec and at_exit
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 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