Created
January 11, 2011 23:35
-
-
Save stepchud/775389 to your computer and use it in GitHub Desktop.
run individual tests to your <3s delight
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
#!/usr/bin/env ruby | |
def rake_test_loader_path | |
"/usr/local/rvm/gems/ruby-1.9.2-p0@global/gems/rake-0.8.7/lib/rake/rake_test_loader.rb" | |
end | |
def test_cmd_pre | |
%|ruby -I'lib:test' '#{rake_test_loader_path}' | | |
end | |
unless File.directory?("test") | |
raise "couldn't find a test directory. sure you're in an app directory?" | |
end | |
unless File.exist?(rake_test_loader_path) | |
raise "couldn't find rake test loader at #{rake_test_loader_path}. did you define this in the script?" | |
end | |
if ARGV.empty? | |
puts "usage: rtest [-v] test_file_path test_name [test_name ...]" | |
puts " rtest [-v] test_file_path [test_file_path ...]" | |
puts "-v option for verbose test mode: prints the name, execution time and result of each test as it runs." | |
puts "file globs will run all matching files, e.g. test/unit/ticket_*.rb" | |
exit | |
end | |
# verbose mode | |
test_opts = (ARGV.first == '-v' ? ARGV.shift : '') | |
cmd = test_cmd_pre + ARGV.first + " #{test_opts}" | |
if ARGV.length > 1 # given a filename with a list of individual tests or several test files to run. | |
if ARGV.all?{|arg| File.exist?(arg)} | |
# given a list of test files to run | |
# rake doesn't seem to have a convenient way to do this and passing args to rake is a PITA | |
puts "Testing several files:\n#{ARGV.join("\n")}" | |
cmd = test_cmd_pre + %|"#{ARGV.join('" "')}" #{test_opts}| | |
else | |
test_file = ARGV.shift | |
puts "Running individual test cases" | |
test_names = [] | |
while (test_name = ARGV.shift) do | |
test_names << Regexp.escape(test_name) | |
end | |
puts test_names.join("\n") | |
cmd = test_cmd_pre + "'#{test_file}' --name='/#{test_names.join('|')}/' #{test_opts}" | |
end | |
end | |
puts cmd | |
exec cmd |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment