Skip to content

Instantly share code, notes, and snippets.

@jamescarr
Created September 6, 2012 20:42
Show Gist options
  • Save jamescarr/3660228 to your computer and use it in GitHub Desktop.
Save jamescarr/3660228 to your computer and use it in GitHub Desktop.
tests.watchr
##
# run: watchr tests.watchr
##
$exec = "php #{Dir.pwd}/vendor/bin/phpunit.php".
watch('(.*).php') { |m| changed(m[0]) }.
def changed(file).
#ignore file, just run all cases in 'tests/'
path = "test/"
run "cd test && #{$exec}"
end.
def run(cmd)..
result = `#{cmd}`.
puts result
notify(result)
end.
def notify(message).
libnotify = "notify-send"
# Get the memory usage and the return status..
message = message.split("\n");
message = message[message.count-1] + " - " + message[message.count-3] + ""
if message.include?("OK (") and !message.include?("FAILURES")
image = "~/.watchr_images/passed.png".
else
image = "~/.watchr_images/failed.png".
end
# Transient makes a temporary message in Gnome Shell, unsure about Unity/KDE
options = "--hint int:transient:1 PHPUnit '#{message}'"
full = %(#{libnotify} #{options} &)
system full.
end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment