Created
November 27, 2013 02:29
-
-
Save chendo/7669779 to your computer and use it in GitHub Desktop.
I wrote a helper that helps one debug `rand`-based test failures by running `srand` with the same number before every test. That way, if a test fails in a full run due to a `rand` issue, by using the same `--seed`, it should fail whether you run just the file or the individual test.
This file contains hidden or 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
class ConsistentRandomness | |
def self.setup_rng | |
if !@seed | |
@seed = srand(1) | |
puts "Using seed #{@seed} for every test" | |
end | |
srand(@seed) | |
end | |
end | |
class ActiveSupport::TestCase | |
before do | |
ConsistentRandomness.setup_rng | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment