I\'m currently testing my mailers with RSpec, but I\'ve started setting up multipart emails as described in the Rails Guides here: http://guides.rubyonrails.org/action_mailer_b
If your email has attachments the text and html parts will end be placed in a multipart/alternative
part. This is noted on under Sending Emails with Attachments in the Rails 3 Guide.
To handle this, I first simplified the get_message_part
method above to:
def get_message_part(mail, content_type)
mail.body.parts.find { |p| p.content_type.match content_type }
end
Then in my test:
multipart = get_message_part(email, /multipart/)
html = get_message_part(multipart, /html/)
html_body = html.body.raw_source
assert_match 'some string', html_body