Hi i am testing email through rspec but some problem occured.
This is the whole scenario:
What i want to do is when my user is created it should send mail to for
activation.
This is the code under user_spec.rb
require File.expand_path(File.dirname(FILE) + ‘/…/spec_helper’)
describe User do
before(:each) do @user = User.create
ActionMailer::Base.delivery_method = :test
ActionMailer::Base.perform_deliveries = true
ActionMailer::Base.deliveries = []
end
fixtures :users
context “User†do
it “should be create if all the credentials are provided†do @user.attributes = valid_user_attributes
mail = Notifier.signup_notification(â€user_1″)
ActionMailer::Base.deliveries.size.should == 1
mail.body.should =~ /Please signup/ @user.should be_valid @user.save
end
Under notifier.rb it contains:
class Notifier < ActionMailer::Base
helper :application #user notification
def signup_notification( user )
setup_email( user.email ) @subject = “Please signup” @body[:user] = user
end
end
Now here Notifier is another model which contains signup_ notification
method.
Is it the case that i would need to test that in notifier spec or is it
possible to get notifier model in user like by using include method
I tried using include like “include Notifier” but is is showing me error
as
user_spec.rb:2:in `include’: wrong argument type Class (expected Module)
(TypeError)
I got the Notifier model included in the user spec like require
‘notifier.rb’
By adding this i can now access Notifier.deliver_signup_notification
method(i checked up in the code and it user deliver before that)
Now i can access the method.
But another problem is i am getting error as "undefined method email' for 327378:Fixnum" in app/models/notifier.rb:5:insignup_notification’
i.e. on this line “setup_email( user.email )”
This means that it is getting the user object.But i have added user in
fixtures.
How can i add this user to point it to notifier object?
Hello all,
I got my problem solved.It was really a simple mistake.
I have a doubt that in development i can send a mail but in while
testing(through Rspec) mail is not getting sent.
Do i need to change some configuration for testing?
Continuing with the topic but scenario is different:
I had written a rake task in rspec.rake.What i want is after running the
task i should get an email
So for that i have created a method in app/models/notifier.rb which is
as follows:
def sanity @recipients = “[email protected]” @subject = “Sanity”
end
Now in the rake task i am calling the method which is a follows (I am
writing this rake task under rspec.rake):
desc “Sanity testing”
Spec::Rake::SpecTask.new(:sanity) do |t|
But if i run the task it says “uninitialized constant Notifier” .If i
comment the notifier line then my rake task is working fine.
May be it is not getting the model.So do i need to add the model or some
configuration need to be done
What are you actually trying to accomplish here? Is this a means of
manually testing that the email gets sent? Or does the email really need
to get sent when running rake tasks for some business purpose other than
testing?
But if i run the task it says “uninitialized constant Notifier” .If i
comment the notifier line then my rake task is working fine.
May be it is not getting the model.So do i need to add the model or some
configuration need to be done
I think that’s pretty clear from the error message.
For the application i have written scripts which i am call from a rake
task.
So i need to know whether how much tests have been passed/failed by
email.
In the mail i will get the count of total tests passed/failed.
For the application i have written scripts which i am call from a rake
task.
So i need to know whether how much tests have been passed/failed by
email.
In the mail i will get the count of total tests passed/failed.
Please quote the relevant parts of the thread so we know what you’re
talking about.
For the application i have written scripts which i am call from a rake
task.
So i need to know whether how much tests have been passed/failed by
email.
For the application i have written scripts which i am call from a rake
task.
So i need to know whether how much tests have been passed/failed by
email.
In the mail i will get the count of total tests passed/failed.
Please quote the relevant parts of the thread so we know what you’re
talking about.
Actually what i want is when my rake task gets executed then i am
calling a notifier_deliver method (which i have defined in
app/models/notifier.rb) which will send mail.
So i want to know how should i do this in Spec task.Since doing normally
in separate rake file it works but it shows error in spec rake file i.e.
in rspec.rake.
Please quote the relevant parts of the thread so we know what you’re
talking about.
Actually what i want is when my rake task gets executed then i am
calling a notifier_deliver method (which i have defined in
app/models/notifier.rb) which will send mail.
So i want to know how should i do this in Spec task.Since doing normally
in separate rake file it works but it shows error in spec rake file i.e.
in rspec.rake.
Let’s try this again:
Please quote the relevant parts of the thread so we know what you’re
talking about.
To clarify: I’m asking you to help me help you by including the parts of
this thread that will help provide context so I can answer you without
having to go digging through my email archives. Earlier this thread you
had examples of code and failure messages. I don’t remember them
exactly, but I remember they were there. Please send a single email that
includes all of the relevant parts of this thread in one email so I (or
anyone else on this list who offers help) don’t have to go digging
through email archives to piece this all together.
Cheers,
David
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.