Skip to content

Instantly share code, notes, and snippets.

@semanticart
Created December 24, 2010 19:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save semanticart/754459 to your computer and use it in GitHub Desktop.
Save semanticart/754459 to your computer and use it in GitHub Desktop.
search the test files for a phrase and run the tests that match
# you'll probably want to alias this in one of your dotfiles
# i.e. alias st="ruby -I\"lib:test\" search_and_test.rb"
#
# the -I"lib:test" can be important if you get complaints like "no such file to load -- test_helper (MissingSourceFile)"
ack_opts = [
"-i", # case insensitive
"-l", # just return file names
"-G _test.rb", # only search files whose name matches /_test.rb/
ARGV.join(' '), # pass along any options we're passed in (usually just the search string)
"test/" # scope our search to the test directory
].join(" ")
test_files = `ack #{ack_opts}`.split("\n")
if test_files.size > 0
puts "Testing: #{test_files.join(" ")}"
test_files.each do |file|
load file
end
else
puts "No matches for #{ARGV.join(" ")}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment