How to test the call of mailer?

Greetings to all. There was such question, you want to test a method call on the controller level:
How to implement it in the case of mailroom where called just 2 methods? The following options, of course, are not:
- expect(ConfirmOauth.email_confirmation(user)).to receive(:deliver_now)
- expect(ConfirmOauth).to receive(:email_confirmation).with(user)
July 8th 19 at 15:23
1 answer
July 8th 19 at 15:25
let(:confirm_oauth) { double deliver_now: nil }
before do
 allow(ConfirmOauth).to receive(:email_confirmation)
 .and_return confirm_oauth
subject! { do_something_that_calls_mailer }

it do
 expect(ConfirmOauth).to have_received(:email_confirmation).with user
 expect(confirm_oauth).to have_received :deliver_now

Another method is a method receive_message_chain It will fit if not you need to check with what parameters was called interim methods.

Find more questions by tags Ruby on RailsRubyRSpec