rspec-email - How to get the body text?

AnApprentice picture AnApprentice · Mar 21, 2011 · Viewed 10.5k times · Source

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

Answer

Alberto F. Capel picture Alberto F. Capel · Mar 22, 2011

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"