使用this Railscast episode,ActiveRecord::RecordNotFound
错误最终会重定向到ErrorsController和/app/views/errors/404.html.erb视图。但是,我在我的一个测试中有以下内容(Item belongs_to List):
scenario "item cannot be created without a list" do
visit new_item_path
# Because it's not the proper nested new_list_item_path(@some_list) path,
# @list is not created in the ItemsController.
page.should have_content('Not Found')
page.status_code.should be 404
end
但是,测试失败并带有以下内容:
Failure/Error: visit new_item_path
ActiveRecord::RecordNotFound:
Couldn't find List without an ID
因此控制器在需要列表时正常工作,但测试失败,因为它没有考虑应该将用户发送到404的自定义异常处理。
如何正确测试重定向?