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 'ma...@mail.com'
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?