Skip to content

Instantly share code, notes, and snippets.

@timcharper
Forked from bmabey/.autotest
Created May 20, 2009 19:53
Show Gist options
  • Save timcharper/115047 to your computer and use it in GitHub Desktop.
Save timcharper/115047 to your computer and use it in GitHub Desktop.
require 'autotest/redgreen'
module Autotest::Growl
def self.notify(title, msg, img)
system("osascript ~/bin/growlNotify.scpt '#{title}' '#{msg.inspect}' '#{img}'")
end
Autotest.add_hook :ran_command do |at|
results = [at.results].flatten.join("\n")
# rpsec
output = results.slice(/(\d+)\s+examples?,\s*(\d+)\s+failures?(,\s*(\d+)\s+pending)?/)
if output
if $~[2].to_i > 0
notify "Test Results", "#{output}", "~/.autotest_images/fail.png", 2
else
notify "Test Results", "#{output}", "~/.autotest_images/pass.png"
end
end
# test::unit
output = results.slice(/(\d+)\s+tests?,\s*(\d+)\s+assertions?,\s*(\d+)\s+failures?,\s*(\d+)\s+errors?/)
if output
if (($~[3].to_i > 0) or ($~[4].to_i > 0))
notify "Test Results", "#{output}", "~/.autotest_images/fail.png", 2
else
notify "Test Results", "#{output}", "~/.autotest_images/pass.png"
end
end
end
end
-- growlNotify.applescript
-- Created by Mike Hagedorn on 2007-10-31.
-- Copyright (c) 2007 Silverchair Solutions. All rights reserved. http://www.silverchairsolutions.com
-- based on script from the growl website
-- works around the fact that growlnotify doesnt work on leopard
-- pass in like osascript growlNotify.applescript
on run argv
set rspectitle to item 1 of argv
set rspecmessage to item 2 of argv
set rspecimage to item 3 of argv
tell application "GrowlHelperApp"
-- Make a list of all the notification types
-- that this script will ever send:
set the allNotificationsList to ¬
{"RSpec Notification"}
-- Make a list of the notifications
-- that will be enabled by default.
-- Those not enabled by default can be enabled later
-- in the ‘Applications’ tab of the growl prefpane.
set the enabledNotificationsList to ¬
{"RSpec Notification"}
-- Register our script with growl.
-- You can optionally (as here) set a default icon
-- for this script’s notifications.
register as application ¬
"Growl-RSpec AppleScript Notifications" all notifications allNotificationsList ¬
default notifications enabledNotificationsList ¬
icon of application "Script Editor"
-- Send a Notification…
notify with name ¬
"RSpec Notification" title rspectitle ¬
description rspecmessage ¬
application name ¬
"Growl-RSpec AppleScript Notifications" image from location rspecimage
end tell
end run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment