在ApplicationController
中,我有要在maintenance_mode_controller_specs
中测试的结果。如何创建模拟maintenance_mode_active
方法,该方法将在规范中返回false?
ApplicationController.rb
def maintenance_mode_active
# ...
feature_flag.active
end
maintenance_mode_controller_spec
context 'when maintenance mode is inactive' do
let(:application_controller) { instance_double(ApplicationController) }
before do
allow(ApplicationController).to receive(:new).and_return(application_controller)
allow(application_controller).to receive(:maintenance_mode_active).and_return(false)
end
it 'redirect to root page' do
get :maintenance_mode
expect(response).to have_http_status(:redirect)
end
end
在上述规格下,我有一个错误:
NoMethodError: nil:NilClass的未定义方法“活动” 你的意思是?行为类似?
这意味着模拟不起作用。