Skip to content

Instantly share code, notes, and snippets.

@rweald
Created March 29, 2011 18:15
Show Gist options
  • Save rweald/892899 to your computer and use it in GitHub Desktop.
Save rweald/892899 to your computer and use it in GitHub Desktop.
This is a simple script that will run spec test suite for files in lib directory. Ideal for testing a gem
first_run = true
def run_test_suite
puts ("rspec spec/")
result = %x[rspec --color spec/]
send_growl_notification(result)
puts result
system('clear')
end
def parse_results(result_string)
result_hash = result_string.match(/([1-9]+) example[s]*, ([0-9]+) failures/).captures
{:failures => result_hash[1], :number_tests => result_hash[0]}
end
def send_growl_notification(result_text)
result_hash = parse_results(result_text)
title = "Test Results"
message = "#{result_hash[:number_tests]} examples, #{result_hash[:failures]} failures"
system(%Q[growlnotify -t "#{title}" -m "#{message}"])
end
#watch the lib directory and if anything changes run the whole test suite
watch('lib/(.*)\.rb'){ run_test_suite}
watch('spec/*') {run_test_suite}
#run the full test suite when watchr is first run
if first_run
run_test_suite
first_run = false
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment