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