Created
September 14, 2011 20:09
-
-
Save nicklewis/1217637 to your computer and use it in GitHub Desktop.
Binary search for order-dependent test failures
This file contains 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
#!/usr/bin/env ruby | |
specs_in_order = File.read('spec_order').split | |
failing_spec = ARGV.first | |
specs = specs_in_order[0...specs_in_order.index(failing_spec)] | |
suspects = specs | |
while suspects.length > 1 do | |
count = suspects.length | |
# Try the first half | |
specs_to_run = suspects[0...(count/2)] | |
puts "Trying #{suspects.join(' ')}" | |
start = Time.now | |
system("rspec #{specs_to_run.join(' ')} #{failing_spec}") | |
puts "Finished in #{Time.now - start} seconds" | |
if $? == 0 | |
puts "Innocent!" | |
# This group is innocent. The culprit is in the other half. | |
suspects = suspects[(count/2)..-1] | |
else | |
puts "Guilty!" | |
# One of these is guilty. | |
suspects = specs_to_run | |
end | |
end | |
puts "The culprit is #{suspects.first}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Create a file in the local directory called 'spec_order', with the list of specs in the order they were run to cause the failure. Pass as an argument to the program the path to the failing spec.