早速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#, "-s"
  28        else
  29          growl "Tests Passed", "#{tests + examples} tests", IMG_OK
  30        end
  31      end
  32    end
  33  end

最初はrequire 'autotest/growl'をしてモンキーパッチを当てていたのですが、 結局ほとんど書きかえてしまったのでこうなりました。

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

posted by Png genki on Mon 15 Sep 2008 at 09:24 with 2 comments
Contents
growlとautotestを連携させる
Comments
瀧内元気: MacOS版は以下にあります * [genki/ViMouse](https://githu... '23-1
dsjf: https://gist.github.com/6bf1bf2c3cbb5eb6e7a7 これ... '13-1
瀧内元気: おお、チェックしてみます。thx! '11-12
overisland: Reeder for iPhone もこの UI を実装していますね。 '11-12
瀧内元気: その情報は見たのですが、以下のサイトによると、現在はまた必要になってるっぽいんですよね。 ... '11-12
Services from s21g
twpro(ツイプロ)
Twitterプロフィールを快適検索
地価2009
土地の値段を調べてみよう
MyRestaurant
自分だけのレストラン手帳
Formula
ブログに数式を埋め込める数式コミュニティ