Created
December 19, 2012 07:41
-
-
Save susanBuck/4335092 to your computer and use it in GitHub Desktop.
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
# Command to run this: watchr /path/to/file/autotest_watchr.rb | |
##### | |
system %(echo "Running autotest_watchr.rb") | |
##### | |
# Watch the Classes folder for changes | |
# If there's a change to a class, look for it's corresponding Test file. | |
# Ex if Shopper.php changes, it'd run the test on ShopperTest.php | |
watch("Classes/(.*).php") do |match| | |
run_test %{Tests/#{match[1]}Test.php} | |
end | |
##### | |
# Also watch for changes to the test files | |
watch("Tests/.*Test.php") do |match| | |
run_test match[0] | |
end | |
##### | |
def run_test(file) | |
clear_console | |
# First, make sure the file exists | |
unless File.exist?(file) | |
puts "#{file} does not exist" | |
return | |
end | |
# Now run the PHPUnit test on the file | |
puts "Running #{file}" | |
result = `phpunit #{file}` | |
puts result | |
if result.match(/OK/) | |
notify "#{file}", "PASSED", "pass.png", 2000 | |
elsif result.match(/FAILURES\!/) | |
notify_failed file, result | |
end | |
end | |
##### | |
def notify_failed cmd, result | |
failed_examples = result.scan(/failure:\n\n(.*)\n/) | |
notify "#{cmd}", failed_examples[0], "fail.png", 6000 | |
end | |
##### | |
def notify title, msg, img, show_time | |
images_dir ='/Users/Susan/Sites/autotest/images/' | |
# Send growl notification | |
system `growlnotify --image "#{images_dir}#{img}" -m "#{title} #{msg}"` | |
end | |
##### | |
def clear_console | |
puts "\e[H\e[2J" | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment