Dependency "watchr":
sudo gem install watchr
On Macs:
sudo gem install growl
Uses notify-send on other systems than Mac.
Call "watchr ./watch.rb" in your project
watch('(.*).php') { |m| code_changed(m[0]) } | |
def code_changed(file) | |
args = if file.end_with?('Test.php') | |
file | |
else | |
"" | |
end | |
run "phpunit --colors " + args.to_s | |
end | |
def run(cmd) | |
result = `#{cmd}` | |
growl result rescue nil | |
end | |
def growl(message) | |
puts(message) | |
message = message.split("\n").last(3); | |
growlnotify = `which growlnotify`.chomp | |
sendnotify = false | |
if growlnotify.empty? | |
sendnotify = true | |
growlnotify = `which notify-send`.chomp | |
end | |
title = message.find { |e| /FAILURES/ =~ e } ? "FAILURES" : "PASS" | |
if title == "FAILURES" | |
image = "~/.watchr_images/failed.png" | |
info = /\x1b\[37;41m\x1b\[2K(.*)/.match(message[1])[1] | |
else | |
image = "~/.watchr_images/passed.png" | |
info = /\x1b\[30;42m\x1b\[2K(.*)/.match(message[1])[1] | |
end | |
if sendnotify | |
options = "-i '#{File.expand_path(image)}' '#{title}' '#{info}'" | |
else | |
options = "-w -n Watchr --image '#{File.expand_path(image)}' --html '#{title}' -m '#{info}'" | |
end | |
system %(#{growlnotify} #{options} &) | |
end |