Skip to content

Instantly share code, notes, and snippets.

@colynb
Created October 15, 2012 00:55
Show Gist options
  • Save colynb/3890329 to your computer and use it in GitHub Desktop.
Save colynb/3890329 to your computer and use it in GitHub Desktop.
Ruby / Watchr / PHPUnit Notifier
#watchr script
# $ watchr ./autotest_watchr.rb
# depends on Growl and growlnotify
watch("Classes/(.*).php") do |match|
run_test %{Tests/#{match[1]}Test.php}
end
watch("Tests/.*Test.php") do |match|
run_test match[0]
end
def run_test(file)
unless File.exist?(file)
puts "#{file} does not exist"
return
end
puts "Running #{file}"
result = `phpunit #{file}`
puts result
if result.match(/OK/)
notify "#{file}", "Tests Passed Successfully", "success.png", 0
else
notify_failed file, result
end
clear_console
end
def notify title, msg, img, sticky
images_dir ='~/icons'
command = "growlnotify"
message = "-m '#{msg}'"
icon = "--icon png --image #{images_dir}/#{img}"
title = "-t '#{title}'"
sticky = ""
if sticky == 1
sticky "-s"
end
system "#{command} #{sticky} #{message} #{icon} #{title}"
end
def notify_failed cmd, result
notify "#{cmd}", result, "error.png", 1
end
def clear_console
puts "\e[H\e[2J" #clear console
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment