Testing mailers with fixtures- still accurate?

Hey guys,

The “Testing Your Mailers” section of the “A Guide to Testing Rails Applications” guide talks about using fixtures to test your mailers (Section 9.2.1 “Revenge of the Fixtures”), and I’m wondering if this is still accurate and a best practice.

In Rails 4.2 when you generate a mailer with an action provided, a unit test will be automatically generated for you. The Rails-generated test does not use a fixture to test the mailer action template but rather tests for individual pieces of content using “assert_match”.

Rails 4.2 generated test

test “invite” do

assert_match “Hi”, mail.body.encoded

end

Rails testing guide

test “invite” do

assert_equal read_fixture(‘invite’).join, email.body.to_s

end

``

The testing guide also mentions that fixture stubs will be automatically created using the mailer generator, but this does not happen.

When you generated your mailer, the generator creates stub fixtures for each of the mailers actions. If you didn’t use the generator you’ll have to make those files yourself.

Lastly, Rails 4.2 now generates an ActionMailer::Preview file which is used to render the output of the mailer actions so they can be visually inspected easily. This is not mentioned in the guides.