Skip to content

Instantly share code, notes, and snippets.

@chendo
Created November 27, 2013 02:29
Show Gist options
  • Save chendo/7669779 to your computer and use it in GitHub Desktop.
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.
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