我已经进行了RSpec测试
let(:mail_instance) { double(deliver_later: nil) }
before do
allow(Confirmationmailer).to receive(:send_email).and_return(mail_instance)
allow(mail_instance).to receive(:deliver_later)
end
it 'calls mailer,and delivers the mail' do
call_endpoint
expect(mail_instance).to have_received(:deliver_later)
end
它运行良好,但出现了rubocop错误-prefer using verifying doubles over normal doubles
。根据文档https://www.rubydoc.info/gems/rubocop-rspec/1.7.0/RuboCop/Cop/RSpec/VerifiedDoubles,我应该改用instance_double
,但如果更改它,我的规格会出错:
ArgumentError: 预期使用模块或字符串,得到{:deliver_later => nil}