简体   繁体   中英

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.

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM