简体   繁体   English

RSpec和测试Devise的邮件

[英]RSpec and testing Devise's mailer

I had some issues with sending confirmation emails in Devise. 我在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. 如果我错过了什么,请告诉我。

This worked for me if you want to have a more explicit test and actually test the email is sent with RSpec. 如果您想要更明确的测试并且实际测试电子邮件是通过RSpec发送的,这对我有用。

it 'sends a confirmation email' do
  user = FactoryGirl.build :user
  expect { user.save }.to change(ActionMailer::Base.deliveries, :count).by(1)
end

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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