Ruby 1.9.3 と Rails 3.2.8 を使用しています。これはレーキ 0.9.2.2 を使用します。
失敗した単体テストを検出したいのですが、Rails 2.3 では、終了コードをチェックすることでこれを行いました。これは機能しなくなりました。
私は試します:
rake test:units TEST=test/unit/failing_test.rb RAILS_ENV=test && echo "OK"
failing_test.rb は、false をアサートする単一のテストで構成されています。テストの失敗が表示され、「OK」が表示されないことを期待していますが、代わりに次のように表示されます。
Started
F
===============================================================================
Failure: <false> is not true.
test: failing test case should fail. (FailingTest)
test/unit/failing_test.rb:6:in `block (2 levels) in <class:FailingTest>'
shoulda-context (1.0.0) lib/shoulda/context/context.rb:398:in `call'
shoulda-context (1.0.0) lib/shoulda/context/context.rb:398:in `block in create_test_from_should_hash'
activesupport (3.2.8) lib/active_support/testing/setup_and_teardown.rb:72:in `block in run'
activesupport (3.2.8) lib/active_support/callbacks.rb:425:in `_run__3774233495015181374__setup__985181848351195933__callbacks'
activesupport (3.2.8) lib/active_support/callbacks.rb:405:in `__run_callback'
activesupport (3.2.8) lib/active_support/callbacks.rb:385:in `_run_setup_callbacks'
activesupport (3.2.8) lib/active_support/callbacks.rb:81:in `run_callbacks'
activesupport (3.2.8) lib/active_support/testing/setup_and_teardown.rb:70:in `run'
===============================================================================
Finished in 0.002753 seconds.
1 tests, 1 assertions, 1 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications
0% passed
363.24 tests/s, 363.24 assertions/s
rake aborted!
Command failed with status (1): [/Users/chris/.rvm/rubies/ruby-1.9.3-p194/b...]
Tasks: TOP => test:units
(See full trace by running task with --trace)
OK
具体的には「Command failed with status (1)」と表示されますが、これも「OK」と表示されるのでレーキに食い込まれそうです。echo $?
実行すると、終了コードが 0 (成功) になることに注意してください。Rails 2.3で発生したように、エラーが発生した場合、終了コードがゼロ以外になると想定しています。