0
votes

I want to test my Mailer model. Letters should be sent to multiple recipients. How to test that messages sent to multiple recipients? I created spec file:

describe SubscribeMailer do
  before(:each) do
   (1..3).to_a.each do  
    FactoryGirl.create(:subscriber)
   end  
  end

let(:post) { @user.posts.create(@attr)}
let(:mail) { SubscribeMailer.new_post(post) }

   #Failure/Error for this test
  it 'subscribers' do
    mail.to.should == Subscriber.all.map(&:email)
  end

end

But I don't know how to write the test.

2

2 Answers

2
votes

In addition to @Trevoke answer, I'd tell you to have a look at this excellent Railscast.

1
votes

In test environment, ActionMailer.deliveries is an array of mail objects that would otherwise have been sent.