Ruby 1.9.2 と Rails 3.2 で、rake test に色をつける。ついでに自動テストも。
仕事で使わないとほんと腰が重い。Ruby 1.9とRails3をやっと使ってみる。
Rails1や2のころはテストを書く作業が大変だった。とくにfixturesのメンテナンスが洒落にならない。最近はfixturesではなくモックを使うプラグインが出て来ているとかで、多少楽になっていればいいなと思う。
試しに作ったプロジェクトで rake test とテストを実行したら色がついてなくて素っ気なさすぎるので、まず成功は緑、失敗は赤で表示するよう設定。ついでにautotestも入れてみよう。
via. http://seanbehan.com/ruby/color-output-with-testunit-autotest-and-ruby-1-9/
RailsプロジェクトのGemfileを修正してテスト実行時に、"test-unit"、"minitest"、minitestで結果表示を書式化する"turn"、"autotest"、以上を使うよう設定。
group :development, :test do gem 'test-unit' gem 'minitest' gem 'turn' gem 'ZenTest' gem 'autotest-rails-pure' end
そんでbundleを実行して必要なGemをインストール。
$ bundle install
test/test_helper.rb に以下を追加。
require 'test/unit/ui/console/testrunner' class Test::Unit::UI::Console::TestRunner def guess_color_availability true end end
テストを走らせてみる。
$ rake test
テスト結果が色付きで表示されれば成功。続いて自動テストを実行する。
$ bundle exec autotest