0
我想測試一下application_controller的私有方法redirect_to
的正確路徑。下面是我試圖做的:如何在不提出請求的情況下測試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
的事情是,這是一個私有方法。我知道這不是測試實施的最佳實踐,但出於某種原因我想這樣做。在我發出請求之前,'response'是'nil',並且我沒有提出請求,因爲應用程序控制器沒有任何動作,只有'before_filter's。 – ciembor
啊,以前沒聽說過。 – kddeisz