Skip to content

Instantly share code, notes, and snippets.

@everton
Last active February 4, 2016 20:58
Show Gist options
  • Save everton/aa4a1fff3c6bc02e266d to your computer and use it in GitHub Desktop.
Save everton/aa4a1fff3c6bc02e266d to your computer and use it in GitHub Desktop.
Minitest running twice when dealing with forks
require 'minitest/autorun'
class TestSuite
def self.before_run
pid = fork do
puts "on fork"
exit 0
end
Process.detach pid
end
end
class MyTestCase < Minitest::Test
TestSuite.before_run
end
class TestTests < MyTestCase
def test_aa
puts "aaa"
end
end
@everton
Copy link
Author

everton commented Feb 4, 2016

The reason for this duplication is that Minitest uses #at_exit to write results (is the only way to deal with exits inside application); To workaround this, calls to Kernel#exit should be replaced by Kernel#exit!, which ignore callbacks).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment