我是RSpec和TDD的新手,我很难编写一个RSpec测试来测试Devise在用户注册后是否真的发送了确认电子邮件。我知道我的应用程序工作正常,因为我已经在开发和生产中对功能进行了物理测试。但是,我仍然需要为此功能编写RSpec测试,并且我不知道如何通过RSpec测试发送确认电子邮件。
factories/user.rb
FactoryGirl.define do
factory :user do
name "Jack Sparrow"
email { Faker::Internet.email }
password "helloworld"
password_confirmation "helloworld"
confirmed_at Time.now
end
endspec/models/user_spec.rb
require 'rails_helper'
RSpec.describe User, type: :model do
describe "user sign up" do
before do
@user = FactoryGirl.create(:user)
end
it "should save a user" do
expect(@user).to be_valid
end
it "should send the user an email" do
expect(ActionMailer::Base.deliveries.count).to eq 1
end
end
end为什么Devise在我创建@user后没有发送确认电子邮件?我的测试返回ActionMailer::Base.deliveries.count = 0。正如我所说的,我是RSpec和TDD的新手,所以我是不是完全遗漏了什么?
发布于 2015-08-11 01:36:12
Devise使用自己的邮件程序,所以如果将测试放在正确的控制器文件中不能单独工作,那么可以尝试使用Devise.mailer.deliveries而不是ActionMailer::Base.deliveries。
https://stackoverflow.com/questions/30876172
复制相似问题