How to test with RSpec if an email is delivered

后端 未结 8 1159
清酒与你
清酒与你 2020-12-25 11:09

I\'d like to test if an email is delivered if I call a controller method with :post. I\'ll use email_spec so I tried this snipped here: http://rubydoc.info/gems/email_spec/1

8条回答
  •  爱一瞬间的悲伤
    2020-12-25 11:35

    I know I'm late to the party with this one, but for future Googlers...

    I think a better solution to this problem is answered here

    The previously accepted answer is testing the Mailer itself (inside the controller spec). All you should be testing for here is that the Mailer gets told to deliver something with the right parameters.

    You can then test the Mailer elsewhere to make sure it responds to those parameters correctly.

    ReservationMailer.should_receive(:confirm_email).with(an_instance_of(Reservation))

提交回复
热议问题