[rspec-users] Testing Email thriugh Rspec

David Chelimsky dchelimsky at gmail.com
Wed Aug 18 09:24:20 EDT 2010

On Aug 18, 2010, at 7:21 AM, Amit Kulkarni wrote:

> jko170 wrote:
>> There is also the excellent email_spec gem:
>> http://github.com/bmabey/email-spec/
> 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 = "amit at test.com"
>    @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|
> #    t.spec_opts = ["--format", "specdoc", "--dry-run"]
>    t.spec_files = FileList['spec/models/sanity_spec.rb']
>    Notifier.deliver_sanity
>  end

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.


More information about the rspec-users mailing list