Forum: RSpec rails3/rspec2: how to write mailer tests?

Posted by nathanvda (Guest)
on 2010-09-02 17:17
(Received via mailing list)
This will sound awfully stupid, but i have no idea how to start
writing any mailer tests.

I have a mailer class

    class SmsMailer < ActionMailer::Base

      def fake_sms(envelope)
        mail(:to => envelope.user.email)
      end
    end

how do I test this?
I tried googling for documentation, but was unable to find something
relevant (probable used wrong search terms).

Or do i just do view-tests on the corresponding view?
Posted by David Chelimsky (Guest)
on 2010-09-02 17:24
(Received via mailing list)
On Sep 2, 2010, at 10:16 AM, nathanvda wrote:

>    end
> 
> how do I test this?
> I tried googling for documentation, but was unable to find something
> relevant (probable used wrong search terms).
> 
> Or do i just do view-tests on the corresponding view?

Start with "script/rails generate rspec:mailer sms" - that will generate 
a stub for you and you can go from there.
Posted by David Chelimsky (Guest)
on 2010-09-02 17:24
(Received via mailing list)
On Sep 2, 2010, at 10:16 AM, nathanvda wrote:

>   end
> 
> how do I test this?
> I tried googling for documentation, but was unable to find something
> relevant (probable used wrong search terms).
> 
> Or do i just do view-tests on the corresponding view?

Start with "script/rails generate rspec:mailer sms" - that will generate 
a stub for you and you can go from there.
Posted by Toni Tuominen (Guest)
on 2010-09-02 17:24
(Received via mailing list)
On Thu, Sep 2, 2010 at 6:16 PM, nathanvda <nathanvda@gmail.com> wrote:
>    end
> http://rubyforge.org/mailman/listinfo/rspec-users
>

What you want is http://github.com/bmabey/email-spec.
Posted by Justin Ko (Guest)
on 2010-09-02 17:28
(Received via mailing list)
On Sep 2, 11:24 am, Toni Tuominen <tjt...@utu.fi> wrote:
> >      end
> > rspec-us...@rubyforge.org
> >http://rubyforge.org/mailman/listinfo/rspec-users
>
> What you want ishttp://github.com/bmabey/email-spec.
> _______________________________________________
> rspec-users mailing list
> rspec-us...@rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users

+1 for the email-spec gem
Posted by nathanvda (Guest)
on 2010-09-03 08:57
(Received via mailing list)
>
> Start with "script/rails generate rspec:mailer sms" - that will generate a stub for you and you can go from there.

I am sorry if that was not clear, but i am using rspec2 and rails.
I did use "rails g mailer SomethingMailer"
and that produced an empty test.

But when i did "rails g mailer SomethingMailer some_mail" i got a good
example.
Feels stupid again :)
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.