1
如何在我的控制器中測試此代碼?我的問題是wizard_incompleted?方法鏈式方法的Rspec測試控制器
class ApplicantsController < ApplicationController
def index
@applicant = current_user.applicant
@application = @applicant.applications.last
if @application.wizard_incompleted?
# some redirect
end
end
end
describe "GET #index" do
let(:application) { double('application')}
it "redirect to wizard if it is incompleted" do
get :index
allow_any_instance_of(application).to receive(:wizard_incompleted?).and_return(true)
expect(response).to redirect_to(new_applicants_application_path)
end
end
給予或採取幾個潛在的拼寫錯誤的 – MilesStanfield
感謝這對我幫助很大! –