On Mon, Mar 26, 2012 at 7:20 PM, Paulo Luis Franchini Casaretto
<pcasare...@gmail.com> wrote:
> 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?

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-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users

Reply via email to