I've a RSpec test
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
And it works well but I've got rubocop error - prefer using verifying doubles over normal doubles. According to docs https://www.rubydoc.info/gems/rubocop-rspec/1.7.0/RuboCop/Cop/RSpec/VerifiedDoubles I should use instance_double instead but if I change it my specs will we falls with an error:
ArgumentError: Module or String expected, got {:deliver_later=>nil}
You need to pass the class you're stubbing to the instance_double:
let(:mail_instance) { instance_double(ActionMailer::MessageDelivery, deliver_later: nil) }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With