刚开始使用Test::Unit
但在确定重定向测试时遇到问题:
test "should destroy line_item" do
assert_difference('LineItem.count', -1) do
delete :destroy, id: @line_item
end
assert_redirected_to controller: 'carts', action: 'show'
end
引发以下错误:
Failure: Expected response to be a redirect to <http://test.host/carts/980190962> but was a redirect to <http://test.host/carts/980190963>.
test_should_destroy_line_item(LineItemsControllerTest)
test/functional/line_items_controller_test.rb:47:in `block in <class:LineItemsControllerTest>'
文档说明以下内容:
assert_redirected_to(options = {}, message=nil) 公共
断言传入的重定向选项与最新操作中调用的重定向选项匹配。这种匹配可以是部分的,这样 assert_redirected_to(:controller => "weblog") 也会匹配 redirect_to(:controller => "weblog", :action => "show") 等的重定向。
但assert_redirected_to controller: 'carts'
导致更彻底的失败:
Failure: Expected response to be a redirect to <http://test.host/carts> but was a redirect to <http://test.host/carts/980190963>.
test_should_destroy_line_item(LineItemsControllerTest)
如果文档是正确的,我错过了什么?如果不是,无论匹配的ID如何,我都必须测试重定向的替代方法是什么?