如果你使用Test:Unit,那么你是否经常会为了它过于唐僧的错误输出而烦恼不已?就像下面这样:
1) Failure:
test_should_be_create(ForumCommentsControllerTest)
method assert_block in assertions.rb at line 48
method _wrap_assertion in assertions.rb at line 495
method assert_block in assertions.rb at line 46
method test_should_be_create in forum_comments_controller_test.rb at line 38
method __send__ in test_case_adapter.rb at line 19
method run in test_case_adapter.rb at line 19
method run in testsuite.rb at line 34
method each in testsuite.rb at line 33
method run in testsuite.rb at line 33
method run in testsuite.rb at line 34
method each in testsuite.rb at line 33
method run in testsuite.rb at line 33
method run_suite in testrunnermediator.rb at line 46
method start_mediator in testrunner.rb at line 67
method start in testrunner.rb at line 41
method run in testrunnerutilities.rb at line 29
method run in autorunner.rb at line 216
method run in autorunner.rb at line 12
at top level in unit.rb at line 278
at top level in forum_comments_controller_test.rb at line 63
response is not a redirection to all of the options supplied (redirection is <{"action"=>"show", "id"=>1, "controller"=>"forums"}>), difference: <{"id"=>"post-2"}>
thoughtbot提供的quietbacktrace gem或许可以帮你减轻一些痛苦:
$ sudo gem install quietbacktrace
要在Rails中使用quietbacktrace,你需要将它解包到vendor目录:
cd rails-app-folder/vendor/gems
gem unpack quietbacktrace
然后在config/environments/test.rb 中添加:
require 'quietbacktrace'
然后再在test/test_helper.rb中添加:
class Test::Unit::TestCase
self.backtrace_silencers << :rails_vendor
self.backtrace_filters << :rails_root
end
好了,现在再次运行测试,你会发现,上面冗长无比的输出已经变成了下面的样子:
1) Failure:
test_should_be_create(ForumCommentsControllerTest)
at top level in forum_comments_controller_test.rb at line 38
at top level in forum_comments_controller_test.rb at line 63
response is not a redirection to all of the options supplied (redirection is <{"action"=>"show", "id"=>1, "controller"=>"forums"}>), difference: <{"id"=>"post-2"}>
当然,如果你偶尔想要回首下往日的艰苦岁月,那也很简单,只需要在test/test_helper.rb中添加:
class Test::Unit::TestCase
self.quiet_backtrace = false
end
再对着天空大喊一句:薄弱波罗蜜,一切就都恢复原样了,更多信息,请看这里。
