salil
April 13, 2009, 5:06pm
1
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 =‘[email protected] ’
@sent_on = Time.now
end
end
Regards
Salil
salil
April 13, 2009, 5:18pm
2
salil
April 13, 2009, 5:25pm
3
David C. wrote:
On Mon, Apr 13, 2009 at 12:06 PM, Salil G. [email protected] wrote:
how to write a spec for an actionmailer method.
Check out GitHub - email-spec/email-spec: Collection of RSpec/MiniTest matchers and Cucumber steps for testing email in a ruby app using ActionMailer or Pony
Cheers,
David
Specifically, look at this example for an idea on how to use it with
RSpec:
require File.dirname(__FILE__) + '/../spec_helper'
# These two example groups are specifying the exact same behavior. However, the documentation style is different
# and the value that each one provides is different with various trade-offs. Run these examples with the specdoc
# formatter to get an idea of how they differ.
# Example of documenting the behaviour explicitly and expressing the intent in the example's sentence.
describe "Signup Email" do
include EmailSpec::Helpers
include EmailSpec::Matchers
include ActionController::UrlWriter
before(:all) do
@email = UserMailer.create_signup("[email protected] ", "Jojo Binks")
end
subject { @email }
it "should be delivered to the email passed in" do
should deliver_to("[email protected] ")
This file has been truncated. show original
-Ben
salil
April 14, 2009, 4:11pm
4
email-spec/examples/rails_root/spec/models/user_mailer_spec.rb at cdf3eeda4d28ef8b35bbce8af9ca7c493528332d · email-spec/email-spec · GitHub
-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’,‘[email protected] ’, 123456)
end
end