我不知道为什么它不起作用。经过几个小时的试图弄清楚这一点,我写了一个小测试来检查ActionMailer :: Base.deliveries是否为空,它是。试图在rSpec中测试电子邮件的发送,但ActionMailer :: Base.deliveries.empty?是真的
当我测试我的重置表单它的工作原理和邮件发送,但是当我运行测试它似乎不存储任何数组中。
require 'spec_helper'
describe "Passwords" do
describe "reset password" do
it "emails user when requesting password reset" do
visit login_path
click_link "Forgot Password?"
response.should render_template "passwords/new"
response.should have_selector :h1, :content => "Reset Password"
fill_in "password_reset[email]", :with => "[email protected]"
click_button "Reset Password"
response.should render_template "users/new"
response.should have_selector :div, :id => "flash_notice", :content => "Email sent with password reset instructions."
ActionMailer::Base.deliveries.empty?.should be_true
# mail = ActionMailer::Base.deliveries.last
end
end
end
在我的'spec_helper.rb'文件中,我必须显式设置'ActionMailer :: Base.delivery_method =:test';你试过这个吗? –
你在spec_helper文件中添加了这个吗?我只是尝试将它添加到RSpec.configure do | config |中块并没有任何效果。 – LondonGuy
我把它放在'config'块之外。我记得有很多问题,我不是100%确定那是固定的。 –