Forum: RSpec how to write a spec for an actionmailer method

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
C42c706fab23da0b6d3cd2cfbb8db27d?d=identicon&s=25 Salil Gaikwad (salil)
on 2009-04-13 17:06
how to write a spec for an actionmailer method.

following is the method of action controller.

class Notifier < ActionMailer::Base

  def conta(username ,adresseemail,code)
    @subject  = 'Admin Confirmation Mail'
    @recipients  = adresseemail
    @body["Username"]= username
    @body["adresseemail"]= adresseemail
    @body[:url]  = "http://192.168.1.58:3002/login/activate/#{code}"
    @from              ='anubhaw@cipher-tech.com'
    @sent_on         =  Time.now
  end

end

Regards

Salil
5d38ab152e1e3e219512a9859fcd93af?d=identicon&s=25 David Chelimsky (Guest)
on 2009-04-13 17:18
(Received via mailing list)
On Mon, Apr 13, 2009 at 12:06 PM, Salil Gaikwad <lists@ruby-forum.com>
wrote:
> how to write a spec for an actionmailer method.

Check out http://github.com/bmabey/email-spec/

Cheers,
David
C694a032be7518a0d704318895f8fe1d?d=identicon&s=25 Ben Mabey (mabes)
on 2009-04-13 17:25
(Received via mailing list)
David Chelimsky wrote:
> On Mon, Apr 13, 2009 at 12:06 PM, Salil Gaikwad <lists@ruby-forum.com> wrote:
>
>> how to write a spec for an actionmailer method.
>>
>
> Check out http://github.com/bmabey/email-spec/
>
> Cheers,
> David
>

Specifically, look at this example for an idea on how to use it with
RSpec:

http://github.com/bmabey/email-spec/blob/cdf3eeda4...

-Ben
C42c706fab23da0b6d3cd2cfbb8db27d?d=identicon&s=25 Salil Gaikwad (salil)
on 2009-04-14 16:11
> 
http://github.com/bmabey/email-spec/blob/cdf3eeda4...
>
> -Ben

I try following and it works. i don't know how but it pass the test
gives me 100% coverage and also i receive a test email.

describe ApplicationHelper do
   it "should use ActionMailer to send a confirmation email" do
      ActionMailer::Base.deliveries=[]
      Notifier.deliver_conta('Salil','salil@cipher-tech.com', 123456)
   end
end
This topic is locked and can not be replied to.