履歴: ソフトウェア/rails/ActiveSupport_TestCase + shoulda によるテスト
各行は、その日時に書かれた内容です。追加・削除は、1 つ前の版との行数の差です (全 13 版)。「差分」は比較する版、「基準」は比べる相手の版を選びます
| 日時 | タイトル | 文字数 | 追加 | 削除 | 内容 | 差分 | 基準 |
|---|---|---|---|---|---|---|---|
| 2014/6/2 9:53:59 | ソフトウェア/rails/ActiveSupport_TestCase + shoulda によるテスト 最新版 | 39,445 | +1 | -1 | 表示 | 差分 | — |
| 2014/6/2 9:53:59 | ソフトウェア/rails/ActiveSupport_TestCase + shoulda によるテスト | 39,451 | +6 | -1 | 表示 | 表示中 | 選択 |
| 2014/5/30 14:33:33 | ソフトウェア/rails/ActiveSupport_TestCase + shoulda によるテスト | 39,363 | +2 | -0 | 表示 | 差分 | 選択 |
| 2014/5/30 14:32:24 | ソフトウェア/rails/ActiveSupport_TestCase + shoulda によるテスト | 39,288 | +116 | -17 | 表示 | 差分 | 選択 |
| 2014/5/30 7:58:45 | ソフトウェア/rails/ActiveSupport_TestCase + shoulda によるテスト | 36,014 | +229 | -0 | 表示 | 差分 | 選択 |
| 2014/5/26 4:31:48 | ソフトウェア/rails/ActiveSupport_TestCase + shoulda によるテスト | 29,846 | +11 | -4 | 表示 | 差分 | 選択 |
| 2014/5/26 4:31:48 | ソフトウェア/rails/ActiveSupport_TestCase + shoulda によるテスト | 29,608 | +30 | -0 | 表示 | 差分 | 選択 |
| 2014/5/24 1:25:48 | ソフトウェア/rails/ActiveSupport_TestCase + shoulda によるテスト | 28,564 | +1 | -1 | 表示 | 差分 | 選択 |
| 2014/5/23 17:42:25 | ソフトウェア/rails/ActiveSupport_TestCase + shoulda によるテスト | 27,825 | +163 | -0 | 表示 | 差分 | 選択 |
| 2014/5/23 13:25:19 | ソフトウェア/rails/ActiveSupport_TestCase + shoulda によるテスト | 21,221 | +174 | -2 | 表示 | 差分 | 基準 |
| 2014/5/23 3:13:32 | ソフトウェア/rails/ActiveSupport_TestCase + shoulda によるテスト | 15,654 | +253 | -88 | 表示 | 差分 | 選択 |
| 2014/5/22 14:25:52 | ソフトウェア/rails/ActiveSupport_TestCase + shoulda によるテスト | 12,435 | +167 | -47 | 表示 | 差分 | 選択 |
| 2014/5/22 13:28:26 | ソフトウェア/rails/ActiveSupport_TestCase + shoulda によるテスト | 9,057 | — | — | 表示 | — | 選択 |
基準: ソフトウェア/rails/ActiveSupport_TestCase + shoulda によるテスト (2014/5/23 13:25:19) → 比較: ソフトウェア/rails/ActiveSupport_TestCase + shoulda によるテスト (2014/6/2 9:53:59)
@@ -9,6 +9,9 @@
これらを使って Rails アプリケーションをテストするためのノウハウをメモとして残したい
+ネットで調べると rspec + shoulda-matchers の記事が多くて、
+MiniTest + shoulda-context + shoulda-matchers の情報になかなかたどり着けないので。。。
+
* 環境 [#ab825549]
現在のこちらの環境は以下の通りです。
@@ -32,6 +35,7 @@
:tapp|上記参照
Gemfile
+ LANG:ruby
group :development do
gem 'better_errors'
gem 'binding_of_caller'
@@ -447,7 +451,7 @@
** I18n.translate の翻訳の抜けを検出する [#ub2cc8f0]
-config/initializers/test_i18n_translation_strictly.rb
+test/test_i18n_translation_strictly.rb
LANG:ruby(linenumber)
# coding: utf-8
@@ -532,11 +536,11 @@
end
end
-** should redirect_to_path [#r6fcffc4]
+** should redirect_to_path と set_the_flash.to の拡張 [#r6fcffc4]
test/shoulda_macros/action_controller_macros.rb
LANG:ruby(linenumber)
- class ActionController::TestCase
+ module Shoulda::Matchers::ActionController # :nodoc:
# shoulda の redirect_to では、
# should redirect_to account_path
@@ -577,6 +581,33 @@
end
end
+ # set_session.to と同様に、
+ # set_the_flash.to{ some_code } の形の呼び出しを可能にする
+ # controller 側の I18n.locale を使ってメッセージを評価するには
+ # set_the_flash.to{ I18n.t :message_id } の形での呼び出しにが必須になる
+ class SetTheFlashMatcher
+
+ alias :to_without_block :to
+ def to(value=//, &block)
+ @value_block = block
+ to_without_block(value)
+ end
+
+ alias :matches_q_without_block :"matches?"
+ def matches?(controller)
+ if @value_block
+ to_without_block( @context.instance_eval(&@value_block) )
+ end
+ matches_q_without_block(controller)
+ end
+
+ def in_context(context)
+ @context = context
+ self
+ end
+
+ end
+
end
*** context_for_all_locales [#r1d0c88f]
@@ -597,6 +628,10 @@
このようなメッセージからエラーが生じたテストの場所を特定するのはなかなか手間がかかります。
+ごたごたは飛ばして解決策へ飛ぶ場合は [[こちら>#s29326e1]]
+
+*** 試行錯誤 [#c418a6e5]
+
で、例外のバックトレースをいじって改善できない物か???と考えたわけです。
ActiveSupport::TestCase ~
@@ -608,20 +643,20 @@
https://github.com/seattlerb/minitest
capture_exceptions で self.failures にエラーを溜めて、~
-https://github.com/seattlerb/minitest/blob/master/lib/minitest/test.rb#L202
+https://github.com/seattlerb/minitest/blob/d5d43cef9a3fd4a0eea972dde125ed5ba1ddb821/lib/minitest/test.rb#L202
to_s で文字に直す?~
-https://github.com/seattlerb/minitest/blob/master/lib/minitest/test.rb#L261
+https://github.com/seattlerb/minitest/blob/d5d43cef9a3fd4a0eea972dde125ed5ba1ddb821/lib/minitest/test.rb#L261
場所を表わす部分は location で、self.failure というのがどこから来るのか分からないものの、
アサート例外の location から得ているように見える~
-https://github.com/seattlerb/minitest/blob/master/lib/minitest/test.rb#L224
+https://github.com/seattlerb/minitest/blob/d5d43cef9a3fd4a0eea972dde125ed5ba1ddb821/lib/minitest/test.rb#L224
failure は Runnable で定義されていた → 何のことはない failures.first のことだった~
-https://github.com/seattlerb/minitest/blob/master/lib/minitest.rb#L345
+https://github.com/seattlerb/minitest/blob/d5d43cef9a3fd4a0eea972dde125ed5ba1ddb821/lib/minitest.rb#L345
Minitest::Assertion 例外の location はここ~
-https://github.com/seattlerb/minitest/blob/master/lib/minitest.rb#L633
+https://github.com/seattlerb/minitest/blob/d5d43cef9a3fd4a0eea972dde125ed5ba1ddb821/lib/minitest.rb#L633
LANG:ruby
module Minitest
@@ -689,7 +724,7 @@
バックトレースに TestCase の行が含まれていない???
-https://github.com/thoughtbot/shoulda-context/blob/master/lib/shoulda/context/context.rb#L356
+https://github.com/thoughtbot/shoulda-context/blob/5305f310d432992e2a1e74f542c62104272edacf/lib/shoulda/context/context.rb#L356
LANG:ruby
def should_not(matcher)
@@ -702,14 +737,21 @@
これだと例外から行番号を得るのは難しいですね。
+*** 解決 [#s29326e1]
+
むしろ、この :name に行番号を突っ込んじゃえばいいという話かも。
+test/shoulda_macros/add_caller_information.rb
LANG:ruby
+ #coding: utf-8
+
module Shoulda
module Context
class Context # :nodoc:
+ # should ブロックの :name に行番号を書き足す
def add_caller_line_number(should)
+ # 現バージョンでは2番目が呼び出し元になるみたい
caller(2).first =~ /:(\d+):in /
should[:name] = should[:name].to_s + " (at line #{$1})"
end
@@ -731,6 +773,12 @@
add_caller_line_number(self.shoulds.last)
end
+ alias :should_eventually_without_caller_information :should_eventually
+ def should_eventually(name, &blk)
+ should_eventually_without_caller_information(name, &blk)
+ add_caller_line_number(self.should_eventuallys.last)
+ end
+
end
end
end
@@ -745,9 +793,496 @@
などというように、should や should_not に対応する行番号が (at line xxx) の形で付くようになりました。
+caller() は遅いので、called_from を作った、という記事がありました。テストの規模が大きい場合には検討の価値があるかもしれません。(このライブラリ、Ruby 1.8 以外に対応していない?)~
+http://magazine.rubyist.net/?0031-BackTrace#l7 ~
+とはいえ1万個の should を作ってようやく1秒違うかどうかなので、気にするだけ損なのかも。
+
+** minitest-focus の代わりに shoulda-focus [#g183283d]
+
+Minitest::Unit によるテストを便利にするための gem として minitest-focus というものがあります。
+
+http://docs.seattlerb.org/minitest-focus/
+
+これは、 編集中のテストケースの中で、ある特定のテストだけを実行したいときに そのテストに focus というキーワードを付けることで、同じテストケースの中の他のテストをすべてスキップできる、という便利な gem です。
+
+特に guard-minitest でテストを自動実行しているときには非常に便利です。
+
+ただ、shoulda-context との組み合わせはどうもよくありません。
+
+そこで、shoulda-context を併用する際に使える focus を以下のように作って使っています。
+
+この記事は Quiita にも載せました。http://qiita.com/osamu_takeuchi/items/256e044a3e802a5abff0
+
+test/shoulda_macros/shoulda-focus.rb
+ LANG:ruby(linenumber)
+ # shoulda-focus.rb
+ #
+ # tested with: shoulda (3.5.0), minitest (4.7.5)
+ #
+ # Marking a context or a should by 'focus'
+ # allows testing only the focused tests,
+ # skipping all other unfocused ones in a TestCase.
+ #
+ # REVISIONS:
+ # 2014-05-30 report number of skipped tests in the result
+ #
+ # EXAMPLE:
+ #
+ # class MyTest < ActionController::TestCase
+ #
+ # should "will not be tested" do assert false end
+ #
+ # context "Unfocused context" do
+ # should "will not be tested" do assert false end
+ #
+ # focus # <<<<<< FOCUSED!
+ # should "will be tested" do assert true end
+ #
+ # should "will not be tested" do assert false end
+ # end
+ #
+ # focus # <<<<<< FOCUSED!
+ # context "Focused context" do
+ # should "will be tested" do assert true end
+ # should "will be tested" do assert true end
+ # should "will be tested" do assert true end
+ # context "Focused sub context" do
+ # should "will be tested" do assert true end
+ # end
+ # end
+ #
+ # end
+ #
+
+ module Shoulda
+ module Context
+
+ class << self
+
+ attr_accessor :focused # indicates we are in a focused context
+ attr_writer :focus_next # indicates focus just called, we will focus the next context/should
+ attr_accessor :focus_used # indicates focus is used, then we will skip unfocused shoulds
+
+ # to see if we should focus the next context
+ def to_focus?
+ # either we are in a focused context or 'focus' was just called
+ result = @focused || @focus_next
+ @focus_next = false
+ result
+ end
+
+ end
+
+ module ClassMethods
+
+ # call this method to mark the next context/should to be focused
+ def focus
+ unless Shoulda::Context.focus_used
+ puts "",
+ " * FOCUS CALLED FOR [#{self.name}] WE WILL SKIP UNFOCUSED TESTS",
+ " " + caller(2).first.sub(/:in .*/, ''),
+ ""
+ end
+ Shoulda::Context.focus_used = true
+ Shoulda::Context.focus_next = true
+ end
+
+ end
+
+ class Context
+
+ alias :initialize_without_focus :initialize
+ def initialize(name, parent, &blk)
+ was_focused = Shoulda::Context.focused
+ Shoulda::Context.focused = Shoulda::Context.to_focus?
+
+ initialize_without_focus(name, parent, &blk)
+
+ Shoulda::Context.focused = was_focused
+ end
+
+ alias :should_without_focus :should
+ def should(name_or_matcher, options = {}, &blk)
+ to_focus = Shoulda::Context.to_focus?
+
+ count_before = shoulds.count
+ should_without_focus(name_or_matcher, options, &blk)
+
+ if shoulds.count > count_before
+ shoulds.last[:focused] = to_focus
+ else
+ should_eventuallys.last[:focused] = to_focus
+ end
+ end
+
+ alias :should_not_without_focus :should_not
+ def should_not(matcher)
+ to_focus = Shoulda::Context.to_focus?
+ should_not_without_focus(matcher)
+ shoulds.last[:focused] = to_focus
+ end
+
+ alias :create_test_from_should_hash_without_focus :create_test_from_should_hash
+ def create_test_from_should_hash(should)
+ if not Shoulda::Context.focus_used or should[:focused]
+ create_test_from_should_hash_without_focus(should)
+ else
+ else
+ # to report skipped tests verbosely, use skip() instead (will be too noisy and slow)
+ # should[:block] = Proc.new(){ skip() }
+ should[:block] = Proc.new(){ increase_skip_count_quietly() }
+ create_test_from_should_hash_without_focus(should)
+ end
+ end
+ end
+ end
+ end
+
+ MiniTest::Unit::TestCase.class_eval do
+ alias :run_without_quiet_skip :run
+ def run(runner)
+ @runner = runner
+ run_without_quiet_skip(runner)
+ end
+
+ def increase_skip_count_quietly()
+ @runner.instance_eval do
+ @skips += 1
+ end
+ end
+ end
+
+* assert_XXX [#h14dab47]
+
+|>|>|>|>|~[[mt>https://github.com/seattlerb/minitest/blob/7e25922c340fa1cfdbeffaf8f37ec020cf6a4fff/lib/minitest/unit.rb#L190]] [[AS>https://github.com/rails/rails/blob/4-0-stable/activesupport/lib/active_support/testing/assertions.rb]] [[AS dep>https://github.com/rails/rails/blob/4-1-stable/activesupport/lib/active_support/testing/deprecation.rb]] [[AD>https://github.com/rails/rails/tree/4-0-stable/actionpack/lib/action_dispatch/testing/assertions]] [[AC>https://github.com/rails/rails/blob/4-0-stable/actionpack/lib/action_controller/test_case.rb#L95]] [[sd>https://github.com/thoughtbot/shoulda-context/blob/master/lib/shoulda/context/assertions.rb]] [[jr>https://github.com/rails/jquery-rails/blob/master/lib/jquery/assert_select.rb]] で実装される assert_xxxx |
+|名前|引数|テスト内容|refuse|実装|
+| assert |test, msg = nil | test | ○ |mt|
+| assert_accepts | matcher, target, options = {} | matcher.matches?(target) | | sd |
+| assert_blank | obj, msg=nil | obj.blank? | | AS |
+| assert_contains | collection, x, extra_msg = "" | x can be regexp | | sd |
+| assert_deprecated | match = nil, &block | | | AS |
+| assert_difference|expression, diff = 1, msg = nil, &block|block 前後で変化||AS|
+| assert_does_not_contain | collection, x, extra_msg = "" | x can be regexp | | sd |
+| assert_dom_equal | expected, actual, message = "" | HTML::Document.new(?).rootを比較 | | AD |
+| assert_dom_not_equal | expected, actual, message = "" | HTML::Document.new(?).rootを比較 | | AD |
+| assert_empty |obj, msg = nil | obj.empty? | ○ |mt|
+| assert_equal |exp, act, msg = nil | exp == act | ○ |mt|
+| assert_generates | expected_path, options, defaults={}, extras = {}, message=nil | | | AD |
+| assert_in_delta |exp, act, delta = 0.001, msg = nil | (act-exp).abs <= delta | ○ |mt|
+| assert_in_epsilon |a, b, epsilon = 0.001, msg = nil | 上の別名 | ○ |mt|
+| assert_includes |collection, obj, msg = nil | collection.include?(obj) | ○ |mt|
+| assert_instance_of |cls, obj, msg = nil | obj.instance_of?(cls) | ○ |mt|
+| assert_kind_of |cls, obj, msg = nil | obj.kind_of?(cls) | ○ |mt|
+| assert_match |matcher, obj, msg = nil | matcher =~ obj | ○ |mt|
+| assert_nil |obj, msg = nil | obj.nil? | ○ |mt|
+| assert_no_difference|expression, msg = nil, &block|block 前後で保存||AS|
+| assert_no_match |matcher, obj, msg = nil | matcher !~ obj | |mt|
+| assert_no_tag | *opts | html_document.find(*opts) | | AD |
+| assert_not |obj, msg = nil|!obj||AS|
+| assert_not_deprecated | &block | | |AS|
+| assert_not_empty |obj, msg = nil | !obj.empty? | |mt|
+| assert_not_equal |exp, act, msg = nil | exp != act | |mt|
+| assert_not_in_delta |exp, act, delta = 0.001, msg = nil | (act-exp).abs > delta | |mt|
+| assert_not_in_epsilon |a, b, epsilon = 0.001, msg = nil | 上の別名 | |mt|
+| assert_not_includes |collection, obj, msg = nil | !collection.include?(obj) | |mt|
+| assert_not_instance_of |cls, obj, msg = nil | !obj.instance_of?(cls) | |mt|
+| assert_not_kind_of |cls, obj, msg = nil | !obj.kind_of?(cls) | |mt|
+| assert_not_nil |obj, msg = nil | !obj.nil? | |mt|
+| assert_not_operator |o1, op, o2 = UNDEFINED, msg = nil | !o1._send_(op, o2) | |mt|
+| assert_not_predicate |o1, op, msg = nil | !o1._send_(op) | |mt|
+| assert_not_respond_to |obj, meth, msg = nil | !obj.respond_to?(meth) | |mt|
+| assert_not_same |exp, act, msg = nil | !exp.equal?(act) | |mt|
+| assert_nothing_raised | | | | |
+| assert_operator |o1, op, o2 = UNDEFINED, msg = nil | o1._send_(op, o2) | ○ |mt|
+| assert_output |stdout = nil, stderr = nil | | |mt|
+| assert_predicate |o1, op, msg = nil | o1._send_(op) | ○ |mt|
+| assert_raise | | | | |
+| assert_raises |*exp | | |mt|
+| assert_recognizes | expected_options, path, extras={}, msg=nil | | | AD |
+| assert_redirected_to | options = {}, message=nil | | | AD |
+| assert_rejects | matcher, target, options = {} | !matcher.matches?(target) | | sd |
+| assert_respond_to |obj, meth, msg = nil | obj.respond_to?(meth) | ○ |mt|
+| assert_response | type, message = nil | | | AD |
+| assert_routing | path, options, defaults={}, extras={}, message=nil | | | AD |
+| assert_same |exp, act, msg = nil | exp.equal?(act) | ○ |mt|
+| assert_same_elements | a1, a2, msg = nil | compare array asif it is set | | sd |
+| assert_select | *args, &block | | | AD |
+| assert_select_email | &block | | | AD |
+| assert_select_encoded | element = nil, &block | | | AD |
+| assert_select_jquery | *args, &block | | | jr |
+| assert_send |[recv, msg, *args], m = nil | recv._send_(msg, *args) | |mt|
+| assert_silent | |assert_output "", "" | |mt|
+| assert_tag | *opts | html_document.find(*opts) | | AD |
+| assert_template | options = {}, message = nil | | | AC |
+| assert_throws |sym, msg = nil | | |mt|
+
+- mt: minitest = https://github.com/seattlerb/minitest/blob/7e25922c340fa1cfdbeffaf8f37ec020cf6a4fff/lib/minitest/unit.rb#L190
+- AS: ActiveSupport = https://github.com/rails/rails/blob/4-0-stable/activesupport/lib/active_support/testing/assertions.rb- AS: ActiveSupport deplication = https://github.com/rails/rails/blob/4-1-stable/activesupport/lib/active_support/testing/deprecation.rb
+- AD: ActionDispatch = https://github.com/rails/rails/tree/4-0-stable/actionpack/lib/action_dispatch/testing/assertions
+- AC: ActionController = https://github.com/rails/rails/blob/4-0-stable/actionpack/lib/action_controller/test_case.rb#L95
+- sd: Shoulda = https://github.com/thoughtbot/shoulda-context/blob/master/lib/shoulda/context/assertions.rb
+- jr: jquery-rails = https://github.com/rails/jquery-rails/blob/master/lib/jquery/assert_select.rb
+
+AD: with_routing ~
+AD: css_select ~
+
+* shouda の matcher [#gd8d5b05]
+
+** 一覧 [#m5e4b4ec]
+
+#multicolumns
+
+*** [[ActiveModel Matchers>https://github.com/thoughtbot/shoulda-matchers#activemodel-matchers]] [#n7a5004d]
+
+-allow_mass_assignment_of
+-''allow_value''
+-ensure_inclusion_of
+-ensure_exclusion_of
+-ensure_length_of
+-have_secure_password
+-validate_absence_of
+-validate_acceptance_of
+-validate_confirmation_of
+-validate_numericality_of
+-validate_presence_of
+-validate_uniqueness_of
+
+#multicolumns
+
+*** [[ActiveRecord Matchers>https://github.com/thoughtbot/shoulda-matchers#activerecord-matchers]] [#x0e4eaa5]
+
+-accept_nested_attributes_for
+-belong_to
+-have_many
+-have_one
+-have_and_belong_to_many
+-have_db_column
+-have_db_index
+-have_readonly_attribute
+-serialize
+
+#multicolumns
+
+*** [[ActionController Matchers>https://github.com/thoughtbot/shoulda-matchers#actioncontroller-matchers]] [#kdd1429f]
+
+-filter_param
+-permit
+-''redirect_to''
+-''render_template''
+-''render_with_layout''
+-rescue_from
+-''respond_with''
+-route
+-''set_session''
+-''set_the_flash''
+-use_after_filter
+-use_after_action
+-use_around_filter
+-use_around_action
+-use_before_filter
+-use_around_action
+
+#multicolumns(end)
+
+始めからコード側で宣言的に書かれている、例えば has_many なんかを
+わざわざテストしても、ほとんどコピペになるだけで意味は薄いと思います。
+
+なので、上記のように matcher はたくさんある物の、頻繁に使うのは、
+
+ActionModel の
+-allow_value
+-- allow_value('http://foo.com', 'http://bar.com/baz').for(:website_url)
+-- allow_value('2013-01-01').for(:birthday_as_string).on(:create)
+-- allow_value('open', 'closed').for(:state).with_message('State must be open or closed')
+
+ActionController の
+
+-redirect_to
+-- redirect_to :list
+-- redirect_to("description") { posts_path }
+-render_template
+-- render_template 'show'
+-- render_template :show
+-respond_with
+-- respond_with 403
+-- respond_with :success
+-- respond_with 500..600
+-route
+-- route(:get, '/posts').to(controller: 'posts', action: 'index')
+-- route(:get, '/posts/1').to('posts#show', id: 1)
+-set_session
+-- set_session :key
+-- set_session(:key).to("value")
+-- set_session(:key).to{ calc_expectation }
+-set_the_flash
+-- set_the_flash
+-- set_the_flash.to('value')
+-- set_the_flash.to(/regexp/)
+-- set_the_flash.to{ calc_expectation_in_string_or_regexp } # 上のコードによる拡張
+-- set_the_flash[:key]
+-- set_the_flash[:key].to('value')
+-- set_the_flash[:key].to(/regexp/)
+-- set_the_flash[:key].now
+-- set_the_flash[:key].to('value').now
+
+くらいかもしれません。
+
+** shoulda-matcher の作り方 [#m38d0482]
+
+shoulda の matcher は matches?, description, failure_message などを実装した
+Matcher オブジェクトを作成するファクトリメソッドとして実装されます。
+
+それが分かっていれば上記 redirect_to_path のように、既存の matcher にパラメータを与えて作成して返すことは簡単にできます。
+
+Matcher クラスを1から自分で作る場合のやりかたは、set_session のコードを見れば一通り分かりそうです。
+
+https://github.com/thoughtbot/shoulda-matchers/blob/master/lib/shoulda/matchers/action_controller/set_session_matcher.rb
+
+* guard-minitest で自動実行 [#wb648c09]
+
+[[guard-minitest>https://github.com/guard/guard-minitest]] は、Rails 4 用の guard-test です。
+guard により、ソースファイルを編集&保存するたびに関連のテストを自動実行することができます。
+
+Rails 4 では標準のテスト環境が Test::Unit から Minitest::Unit に変更になったため、
+guard-test が動かなくなり、代わりに開発されているのが guard-minitest のようです。
+
+- http://bitplaying.tumblr.com/post/55711657471/rails-4-defaults-to-minitest-frustration-follows
+
+ LANG:console
+ $ jed Gemfile
+ group :development do
+ gem 'guard-minitest'
+ end
+ $ bundle install
+ $ bundle exec guard init minitest
+ $ jed Guardfile
+ # Rails 4 となっている部分を有効にする
+ $ bundle exec guard
+ 05:47:51 - INFO - Guard is using TerminalTitle to send notifications.
+ 05:47:51 - INFO - Guard::Minitest 2.3.0 is running, with Minitest::Unit 4.7.5!
+ 05:47:51 - INFO - Running: all tests
+ Run options: --seed 40183
+
+ # Running tests:
+
+ ...
+
+ 05:47:56 - INFO - Guard is now watching at '(Rails root)'
+ [1] guard(main)>_
+
+別のコンソールから、
+
+ LANG:console
+
+ $ touch app/controllers/account_controller.rb
+
+
+とすると元の窓で、
+
+ LANG:console
+
+ 05:49:07 - INFO - Running: test/controllers/account_controller_test.rb
+
+ Run options: --seed 43771
+
+ # Running tests:
+
+ ...
+
+ [1] guard(main)>_
+
+ちゃんとテストが自動実行されました。
+
+恐らく、ファイルを編集する窓と、テスト結果を表示する窓とを開いておいて、
+保存する度に横目でテスト結果を確認するような使い方になりそうです?
+
+** たしかに自動実行はされるけど [#bf45d0f5]
+
+例えば app/models/account.rb を編集すると test/models/account_test.rb が実行されるだけで、Account モデルを使う app/controllers/account_controller.rb のテストまで自動実行されるわけではありません。
+
+実際のところ、account_controller_test.rb も合わせて実行するように設定することまでなら簡単にできそうですが、ちゃんと依存関係をたどってその他のコントローラや統合テストまで起動するのは恐らく簡単にはできないのだと思います。
+
+ですから、app/models/account.rb の編集が一段落したら、例えば application_controller.rb に touch して全テストを実行する(そのように設定しておいて)といった使い方になるんだと思います。
+
+guard で全テストを実行するには、"guard(main)>" のプロンプトで何も入力せず ENTER キーを押せばよいので、そういう用途にも楽ちんに対応できますね。
+
+** 表示を見やすくする [#gbbca72e]
+
+[[minitest-reporters>https://github.com/kern/minitest-reporters]] を使うと結果をカラー表示にできるようです。
+
+- http://stackoverflow.com/questions/7959523/can-minitest-do-something-like-rspec-color-format-doc
+
+ LANG:console
+ $ jed Gemfile
+
+ group :test do
+ ...
+
+ gem 'minitest-reporters'
+
+ end
+
+ $ bundle install
+ $ jed test/test_helpder.rb
+ ...
+
+ require "minitest/reporters"
+ Minitest::Reporters.use!
+ ...
+ $ bundle exec guard
+
+ここには載せませんが、確かに出力がカラーになりました。
+
+* should_eventually と skip() [#m30d873b]
+
+shoulda-context の機能に should_eventually というのがあって、
+通常 should と書くところを should_eventually と書いておく、
+あるいは、should に名前だけ付けて do end を与えないことで、
+ビヘイビャーを記述しつつ、実装を後から行うようにできます。
+
+ LANG:ruby
+ should_eventually "be implemented in the future" do # should_eventually
+ assert false # will not be tested for now
+ end
+
+ should "be implemented in the future, too" # should without body
+
+このときテスト画面には、
+
+ LANG:console
+ * DEFERRED: should be implemented in the future (at line 139).
+ * DEFERRED: should be implemented in the future, too (at line 143).
+
+というような表示を残すのみで、テストとしてはカウントされません。
+
+一方、MiniTest::Unit::TestCase には skip() という関数が用意されていて、
+テスト関数から skip() を呼ぶことで MiniTest::Skip という例外を投げることができて、
+そのテスト関数の以降のテストをキャンセルできます。このとき、テストは skipped としてカウントされます。
+
+ LANG:ruby
+ should "be implemented in the future" do
+ skip() # cancel testing
+ assert false # this assertion will not be tested for now
+ end
+
+当分実装しなさそうな、しばらくの間完全に忘れていて良い仕様については
+should_eventually または do end なしの should で記述しておけばよく、
+
+逆にペンディングになっている仕様があることを目立たせたければ skip() を使えば良いのだと思います。
+
+* RSpec の方が良いんでしょうか [#m55d50d7]
+
+Web 上で情報を探していると、RSpec の記事の方がたくさん目にとまります。
+
+長いものには巻かれておいた方が良いのかもしれません。
+
* 役立ちそうな記事 [#x64e134e]
- http://www.railstips.org/blog/archives/2009/02/21/shoulda-looked-at-it-sooner/
+- http://d.hatena.ne.jp/language_and_engineering/20091023/p1
+- http://www.atmarkit.co.jp/ait/articles/1112/22/news132.html
+- http://guides.rubyonrails.org/testing.html
+- http://maskana-soft.com/rails/pro/detail/test
* コメント [#yfa709ad]