Skip to content

Instantly share code, notes, and snippets.

@thomasjachmann
Created June 7, 2012 15:08
Show Gist options
  • Save thomasjachmann/2889301 to your computer and use it in GitHub Desktop.
Save thomasjachmann/2889301 to your computer and use it in GitHub Desktop.
run failing tests from a test/unit output (eg from rake test:units > units.txt)
require "active_support/inflector"
TESTDEF_REGEX = %r|^([a-z_]+)\(([a-zA-Z]+)\)|
test_methods = []
test_files = []
arg = ARGV.shift
if match = arg.strip.match(TESTDEF_REGEX)
test_methods << match[1]
test_files = Dir.glob("test/**/#{match[2].underscore}.rb").map {|f| f[0..-4]}
else
test_method = nil
IO.readlines(arg).each do |line|
if match = line.match(TESTDEF_REGEX)
test_methods << test_method = match[1]
elsif test_method && match = line.match(%r|^[ \[]+/(.*)\.rb:[0-9]+:in `#{test_method}'|)
test_files << match[1]
test_method = nil
end
end
test_files.uniq!
end
puts "running #{test_methods.size} tests in #{test_files.size} files"
ARGV << "-n"
ARGV << "/#{test_methods.join("|")}/"
test_files.each do |test_file|
require test_file
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment