早速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'をしてモンキーパッチを当てていたのですが、
結局ほとんど書きかえてしまったのでこうなりました。

エラーが発生した場所や、エラーメッセージなんかも表示できるようになるともっと便利になるかもしれないですね。

posted by genki genki on Mon 15 Sep 2008 at 07:40 with 2 comments
瀧内元気 瀧内元気 09/16 07:59
**補足**

-H で接続するようにする場合は、以下のように、Growlの設定画面で

![growl-conf](http://img.skitch.com/20080915-qqfb9w7s1jc2pw8fa5nx2wft4i.jpg)

「受信される通知を聞く」をチェックしておく必要があるようです。
maiha maiha 03/11 16:09
それでもセグブる → osx再起動 → 治った♪

ありがとう!!