Hi Gleb Your original code used partial doubles, which of course are fragile to this kind of change. You should be able to work with them if you want, but the assertion you mention is exactly what the new `have_enqueued_mail` does, https://github.com/rspec/rspec-rails/blob/master/lib/rspec/rails/matchers/have_enqueued_mail.rb which is probably a better way to test.
Cheers Jon Rowe --------------------------- [email protected] jonrowe.co.uk On 14 February 2019 at 13:36, [email protected] wrote: > Hi Jon, > > Before refactoring to use ParameterizedMailers, I had the following code: > > AppointmentMailer.reminder(@appointment, @user). > deliver_later > > > > with the corresponding test: > > expect(AppointmentMailer).to(receive(:reminder).with(appointment, > user)).and_return(appointment_reminder_email) > > Once I switched to ParameterizedMailers, my code changed to: > > AppointmentMailer.with(appointment: @appointment, recipient: > @user).reminder.deliver_later > > With this change, the Mailer is invoked with the .with() method, which means > the test will not trigger the receive(:reminder). I tried doing something > like this: > > expect(AppointmentMailer).to(receive(:with).with(appointment: appointment, > recipient: user)).and_return(parameterized_appointment_mailer) > > However this didn't work as intended because the .with() method returns a new > Parameterized::Mailer. I wish to write a test that checks that the parameters > were passed to the AppointmentMailer and that the reminder method was called > and returned the correct object ( in this example that would be the > appointment_reminder_email). > > The minitest assert method is useful because it accepts the parameters as > arguments: > > def > test_parameterized_email > assert_enqueued_email_with > AppointmentMailer, :welcome, > > args > : {appointment: appointment, recipient: user} do > > AppointmentMailer.with(appointment: appointment, recipient: user).reminder. > deliver_later > > end > end > > > Does this clarify my use-case? > If there is a better way to test my Mailers in general, please let me know! > > Best, > Gleb > > > > On Wednesday, 13 February 2019 18:14:30 UTC+1, Jon Rowe wrote: -- You received this message because you are subscribed to the Google Groups "rspec" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/rspec/dejalu-217-3e40f7db-e4c4-4539-b7ef-d4f683341476%40jonrowe.co.uk. For more options, visit https://groups.google.com/d/optout.
