我正在使用 Ruby 1.9.3 和 Rails 3.2.8。这使用 rake 0.9.2.2。
我希望检测失败的单元测试,在 Rails 2.3 中,我们通过检查退出代码来做到这一点。这不再有效。
我尝试:
rake test:units TEST=test/unit/failing_test.rb RAILS_ENV=test && echo "OK"
failed_test.rb 由一个断言为假的测试组成。我希望看到测试失败而不是看到“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
具体来说,我看到“命令失败,状态为 (1)”,但这似乎被 rake 吃掉了,因为我也看到了“OK”。请注意,如果我这样做echo $?
,我会看到退出代码为 0(成功)。我试图让它在我们的持续集成和发布脚本的上下文中工作,两者都假设在发生错误的情况下退出代码将是非零的,就像 Rails 2.3 发生的那样。