Mac OSX El CapitanでGuardからテスト結果の通知を受け取ってデスクトップに表示する
Railsアプリケーションの開発環境で、Guard
で自動化したテストの結果をデスクトップに通知できるように設定しました。
環境は、Ruby2.3.0とRails4.2.6で、RubyのテストフレームワークはRspecを使ってます。
目次
Homebrewでterminal-notifierを入れる
terminal-notifier
は、コマンドラインツールからMacの通知を使えるようにできる素晴らしい代物で、Homebrew
からインストールできるようです。
$brew search terminal-notifier
terminal-notifier
ちゃちゃっと醸造します。
$brew install terminal-notifier ==> Downloading https://homebrew.bintray.com/bottles/terminal-notifier-1.6.3.el_capitan.bottle.tar.gz ######################################################################## 100.0% ==> Pouring terminal-notifier-1.6.3.el_capitan.bottle.tar.gz ==> Caveats .app bundles were installed. Run `brew linkapps terminal-notifier` to symlink these to /Applications. ==> Summary 🍺 /usr/local/Cellar/terminal-notifier/1.6.3: 12 files, 2.1M
Gemfileにterminal-notifier-guardを追加する
Gemfileのdevelopment
に、terminal-notifier-guard
を追加します。
$vi Gemfile group :development, :test do gem 'rspec-rails', '3.4.2' gem 'guard', '2.13.0' gem 'guard-rspec', '4.6.5' end group :development do gem 'terminal-notifier-guard', '~> 1.6.1' end
Railsチュートリアルでは、通知用のgemはtest
に追加されていましたが、GuardのWikiでdevelopment
に追加してあったので、その通りにしました。
terminal-notifier-guard
のバージョンは、公式のGemfileへの追加の部分に書いてある通りにしてます。
guard
やrspec
のバージョンも、とりあえず最新*1にしてます。
Guardからの通知を確認する
bundle install
とかbundle update
とかした後に、Railsチュートリアルを参考にGuardの設定をして、起動*2させます。
$guard 14:17:05 - INFO - Guard::RSpec is running [1] guard(main)>
適当にファイルを変更して、テストが自動で実行されるか確認します。
14:17:23 - INFO - Running: spec/requests/static_pages_spec.rb The RUBYGEMS_GEMDEPS environment variable is set. This enables RubyGems experimental Gemfile mode, which may conflict with Bundler and cause unexpected errors. To remove this warning, unset RUBYGEMS_GEMDEPS. Running via Spring preloader in process 6449 ...... Finished in 0.32428 seconds (files took 5.87 seconds to load) 6 examples, 0 failures [1] guard(main)>
ターミナルになにやらずらずらと表示された後、デスクトップの右上に格好良い通知が表示されました(๑•̀ㅂ•́)و✧
参考記事
terminal-notifier-guard
については、こちらの記事を参考にさせていただきました。
- Gurad + RSpecで結果をデスクトップ通知する - もはや芽は枯れた
- GitHub - guard/guard: Guard is a command line tool to easily handle events on file system modifications.
- GitHub - Codaisseur/terminal-notifier-guard: Mac OS X User Notifications for Guard
- GitHub - julienXX/terminal-notifier: Send User Notifications on Mac OS X 10.8 from the command-line.
Ruby on Railsチュートリアルは、最新*3の第3版ではなく第2版を参考にしています。 railstutorial.jp