[rspec-rails] Mailer tests should be similar to Controller tests

157 views
Skip to first unread message

Paulo Luis Franchini Casaretto

unread,
Mar 26, 2012, 8:20:33 PM3/26/12
to rs...@googlegroups.com

Hey,

When I'm testing a controller, I basically test three things.
Does it assign the variables the view needs?
Does it render the right template?
Does it do whatever the action is supposed to do?
And when testing mailers I feel it should be basically the same.
Does it assign the variables the view needs?
Does it render the right template?
Does it set the right headers?
I don't want to test the actual mail object, the same way I don't want to test the views in controller tests.
On the other hand, the mail object IS the output of the mailer, so I don't know.
What do you guys think about this?

David Chelimsky

unread,
Mar 29, 2012, 7:55:57 AM3/29/12
to rspec-users

Seems reasonable, but unlikely to change. Here's why. rspec-rails
provides wrappers around test classes provided by rails. Rails
functional tests support the three questions you pose above, but rails
mailer tests are different. From
http://guides.rubyonrails.org/action_mailer_basics.html: "Testing
mailers normally involves two things: One is that the mail was queued,
and the other one that the email is correct."

To support what you'd like to see in mailer specs, rspec-rails would
have to provide it's own ExampleGroup (rather than wrap the rails
class), which would have to be tightly bound to rails' internals. I
took great pains in rspec-rails-2 to constrain coupling to public
APIs, and this has had a big payoff: we've only had one case where a
rails 3.x release required a release of rspec-rails (i.e. there was a
breaking change). With rails-2, pretty much every release broke
rspec-rails because rspec-rails was tied to internals (rspec-rails'
fault, not rails).

If you really want to see this change, you'll need to get it changed
in rails itself, at which point rspec-rails will happily wrap the new
and improved MailerTestCase.

HTH,
David
_______________________________________________
rspec-users mailing list
rspec...@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users

Reply all
Reply to author
Forward
0 new messages