Skip to content

Instantly share code, notes, and snippets.

@proofek
Created March 9, 2011 10:45

Revisions

  1. proofek created this gist Mar 9, 2011.
    28 changes: 28 additions & 0 deletions watchr.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@
    watch('./(.*).php') { |m| code_changed(m[0]) }

    def code_changed(file)
    run "phpunit"
    end

    def run(cmd)
    result = `cd Test && #{cmd}`
    growl result rescue nil
    end

    def growl(message)
    puts(message)
    message = message.split("\n").last(3);
    growlnotify = `which growlnotify`.chomp

    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

    options = "-w -n Watchr --image '#{File.expand_path(image)}' --html '#{title}' -m '#{info}'"
    system %(#{growlnotify} #{options} &)
    end