warning: contains shameless self promotion
This isn't directly addressing your question, but you might want to look at
something like the Wisper gem <https://github.com/krisleech/wisper>, it
allows you to decouple the sending of the email from the `User` model,
which means you can test the different parts in isolation.
In general `after_save` callbacks in models will make testing more
difficult. The trade off is you move away from the Rails golden path.
On Sunday, 27 July 2014 19:38:11 UTC+1, Sandy Y. wrote:
>
> rspec testing of sending email as delayed job in Rails 4, help with
> reviewing test spec and deciphering rspec error message. I'm working
> backwards here where I have working code but the test I am writing for it
> is not passing:
>
> I'm carrying out a unit test on my model:
>
> class Inbound_Email < ActiveRecord::Base
> belongs_to :user
> after_create :send_confirmation_email
>
> private
>
> def :send_confirmation_email
> # create delay job that sends a confirmation to the user who wrote in
> # confirmation_email is the email template to be used
> UserMailer.delay.confirmation_email(self.id)
> end
>
> end
>
> ---------------------------------------------
> here is my rspec file
>
> require 'spec_helper'
>
> describe Inbound_Email do
> before(:each) do
> Delayed::Worker.delay_jobs = false
> message = FactoryGirl.create(:message)
> end
>
> it "queues confirmation mail job when a inbound email is received" do
> mock_delay = double('mock_delay').as_null_object
> UserMailer.any_instance.stub(:delay).and_return(mock_delay)
> mock_delay.should_receive(:send_confirmation_email)
> Delayed::Job.count.should == 1
> end
>
> end
> _________________________________________
>
> here is my factory girl file for message:
>
> FactoryGirl.define do
>
> factory :message do
>
> user
>
> to ["mail@#{EMAIL_URI}"]
>
> from '[email protected] <javascript:>'
>
> subject 'email subject'
>
> raw_html ''
>
> raw_text ''
>
> end
>
>
> -----------------------------------------------------------------------------------
>
> I am getting the following error when running the spec:
> Failure/Error: message = FactoryGirl.create(:message)
> ArgumentError:
> An SMTP To address is required to send a message. Set the message
> smtp_envelope_to, to, cc, or bcc address.
> # ./app/models/user.rb:54:in `send_welcome_email'
> # ./spec/models/message_spec.rb:6:in `block (2 levels) in <top (required)>
>
>
> ----------------------------------------------------------------------------------------------
>
> I have googled the error message but there weren't any helpful info
> online. Am I testing correctly? and if so, how do I pass the test?
>
--
You received this message because you are subscribed to the Google Groups
"rspec" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/rspec/e7b9f96c-6894-4597-8ef5-36c94f6c4fa6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.