Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RSpec and testing Devise's mailer

I had some issues with sending confirmation emails in Devise. That's why I would like to write tests for this functionality. How could I do this, when I don't create my own mailers?

EDIT

I decided, that this should be enough:

it 'should send an email' do
  user
  put :complete, params
  user.send(:send_confirmation_notification?).should == true
end

Please, let me know if I missed something.

like image 670
ciembor Avatar asked Jun 04 '13 11:06

ciembor


2 Answers

Have you looked at the tests which have been written for Devise?

https://github.com/plataformatec/devise/blob/master/test/mailers/confirmation_instructions_test.rb

like image 151
ahmet Avatar answered Nov 06 '22 17:11

ahmet


This worked for me if you want to have a more explicit test and actually test the email is sent with RSpec.

it 'sends a confirmation email' do
  user = FactoryGirl.build :user
  expect { user.save }.to change(ActionMailer::Base.deliveries, :count).by(1)
end
like image 40
kmanzana Avatar answered Nov 06 '22 19:11

kmanzana