【发布时间】:2011-12-19 03:33:30
【问题描述】:
我不知道为什么它不起作用。经过数小时试图弄清楚这一点后,我编写了一个小测试来检查 ActionMailer::Base.deliveries 是否为空。
当我测试我的重置表单时,它可以工作并发送邮件,但是当我运行测试时,它似乎没有在数组中存储任何内容。
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 => "foobar@gmail.com"
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|阻止,它没有任何效果。
-
我把它放在
config块之外。我记得有很多问题,我不能 100% 确定这就是解决问题的原因。 -
不走运,我已经玩了好几个小时了。表单可以正常工作,但希望我的测试能够正常工作
-
那么,您的测试不应该读取
ActionMailer::Base.deliveries.empty?.should be_false以符合您的代码吗?
标签: ruby-on-rails ruby-on-rails-3 rspec ruby-on-rails-3.1 rspec2