早速Growlとautotestを連携させてみようと思ったのですが、
growlnotify-1.1.4でメッセージを出そうとすると、
pre>>
% growlnotify -m "test"
2008-09-15 09:13:20.929 growlnotify[901:10b] could not find local GrowlApplicationBridgePathway, falling back to NSDNC
<<--
こんな感じのWARNINGが出てきます。
メッセージ自体はきちんと表示されるので、実用上問題ないのですが、
毎回警告が出てくるのはちょっと気になるので、
警告が出ない方法が無いかいくつか試してみた所、
以下のようにホストを指定すると大丈夫なようでした。
pre>>
% growlnotify -m "test" -H localhost
<<--
ということで、autotestと連携させるために、
以下のような.autotestファイルを作成しました。
ruby>>
class Autotest
module Growl
IMG_OK = '/Developer/Examples/Carbon/Dial/English.lproj/' +
'rotate_knob_select.tiff'
IMG_NG = "/Applications/Mail.app/Contents/Resources/Caution.tiff"
class << self
def growl(title, msg, img = nil, pri = 0, sticky = "")
img ||= IMG_NG
msg += " at #{Time.now.strftime('%Y-%m-%d %H:%M:%S')}"
system "growlnotify -n autotest #{title} -m #{msg.inspect}" +
" -H localhost --image #{img} -p #{pri} #{sticky}"
end
end
Autotest.add_hook :run_command do |at|
growl "autotest running", "Started", IMG_OK
end
Autotest.add_hook :ran_command do |at|
result = [at.results].flatten.join("\n")
examples = result.slice(/(\d+)\s+examples?/).to_i
tests = result.slice(/(\d+)\s+tests?/).to_i
failures = result.slice(/(\d+)\s+failures?/).to_i
errors = result.slice(/(\d+)\s+failures?/).to_i
if failures + errors > 0
growl "Tests Failed",
"#{failures} failures #{errors} errors", IMG_NG, 2#, "-s"
else
growl "Tests Passed", "#{tests + examples} tests", IMG_OK
end
end
end
end
<<--
最初はrequire 'autotest/growl'をしてモンキーパッチを当てていたのですが、
結局ほとんど書きかえてしまったのでこうなりました。
エラーが発生した場所や、エラーメッセージなんかも表示できるようになるともっと便利になるかもしれないですね。