I'm using rspec with the email-spec gem. I'm trying to do:
last_delivery = ActionMailer::Base.deliveries.last
last_delivery.body.should include "This is the text of the email"
But that doesn't work, is there a way to say body, text version? Content-Type: text/text?
Thanks
Body is actually a Mail::Body instance. Calling raw_source on it should do the trick:
last_delivery = ActionMailer::Base.deliveries.last
last_delivery.body.raw_source.should include "This is the text of the email"
After trying all the above options and failing to get it working (Rails 3.2.13), I found some info in the ruby guide (section 6 is on testing with TestUnit) and got this to work exactly as needed:
last_delivery = ActionMailer::Base.deliveries.last
last_delivery.encoded.should include("This is the text of the email")
Hope that helps!
If you have an html template (example.html.erb) you could use:
last_delivery.html_part.body.to_s
Or, if you have a plain-text (example.text.erb) template:
last_delivery.text_part.body.to_s
Source: In Rails why is my mail body empty only in my test?
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