Testing ActionMailer

Angelegt von suung Mon, 30 Aug 2010 12:17:00 GMT

I am searching for a good solution to automatically test multipart - emails in Rails.

This brought me to that article which didn't help me but summarized some basics of how to test your ActionMailer:

First of all: Test, whether mails have been sent

ActionMailer::Base.deliveries # []

ActionMailer::Base.delieveries.last # TMail...

ActionMailer:;Base.delieveries.last.body.match "my cool string"

Second: Bring your Test - Environment to send your mails

 

 







def setup

    ActionMailer::Base.delivery_method = :test

    ActionMailer::Base.perform_deliveries = true

    ActionMailer::Base.deliveries = []


    @expected = TMail::Mail.new

    @expected.set_content_type "text", "plain", { "charset" => CHARSET }

  end

Also it's worth to read the Wikibook about Action Mailer.

And this is, how it goes:


 

 should('be multipart') do

      assert ActionMailer::Base.deliveries.last.header["content-type"].to_s.match('multipart')

  end

Test for successful email delivery in Rails (ActionMailer)

Angelegt von suung Sun, 15 Aug 2010 23:35:00 GMT

If you want to find out in your functional tess, wether your ActionMailer delivers the rght message, withput involving your friends or customers into the testing process:

 

 

  

        assert message = ActionMailer::Base.deliveries.last

        assert message.to.first =~ /foo-bar@example\.com/

        assert_equal I18n.t('email_verification_message.subject'), message.subject