Created
September 30, 2016 09:09
-
-
Save jdickey/80a6582e20fd74c54a75ad8f760a0145 to your computer and use it in GitHub Desktop.
Got an intermittent failure in your tests for a source file? Try this
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
# Run this inside Pry or irb and let it find a randomisation seed that will | |
# cause your tests to fail. This assumes that you're running tests for a single | |
# test file, which you pass in as the argument to `run_tests`. | |
# | |
# Why don't we collect a whole bunch of failing seeds? You'll need to run this | |
# each time you make a material change to the code being run by the tests, or to | |
# the tests themselves; with that in mind, take one step at a time. | |
# | |
# A quick hack, but feedback appreciated. | |
$used_seeds ||= [] | |
def run_tests(filename) | |
seeds = Array.new(2000) { rand(65536) }; | |
seeds.each do |seed| | |
# cmdline = %{ruby -e 'require "#{filename}"' -- --seed #{seed}} | |
cmdline = 'bin/rake test' | |
unless system(cmdline) | |
puts "Failed seed was #{seed}" | |
break seed | |
end | |
$used_seeds << seed | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment