我想测试一下来自application_controller redirect_to
正确路径的私有方法。这是我试图做的:
describe 'application is complete' do
it 'redirects to the mortgage application show page' do
controller.send(:load_mortgage_application)
expects(controller).to receive(:redirect_to).with(mortgage_application_path(controller.locale, mortgage_application))
end
end
但我得到错误:
RuntimeError:
ActionController::RackDelegation#status= delegated to @_response.status=, but @_response is nil: ...
如何在没有回复的情况下进行测试?
//这个工作:
it 'redirects to the mortgage application show page' do
controller.expects(:redirect_to).with(mortgage_application_path(controller.locale, mortgage_application))
controller.send(:load_mortgage_application)
end
答案 0 :(得分:0)
首先,我假设您需要在控制器规范内,以便您可以使用get:load_mortgage_application。那时你可以这样做:
response.should redirect_to '/scorecard'
或更新的语法:
expect(response).to redirect_to '/scorecard'