2

我不知道为什么它不起作用。经过几个小时的试图弄清楚这一点,我写了一个小测试来检查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 
+0

在我的'spec_helper.rb'文件中,我必须显式设置'ActionMailer :: Base.delivery_method =:test';你试过这个吗? –

+0

你在spec_helper文件中添加了这个吗?我只是尝试将它添加到RSpec.configure do | config |中块并没有任何效果。 – LondonGuy

+0

我把它放在'config'块之外。我记得有很多问题,我不是100%确定那是固定的。 –

回答

1

我似乎总是傻傻的做这样的事情:

因为我创造了passwords_spec手动档,而不是使用RSpec的发电机我忘了加上“要求‘spec_helper’”在该文件的顶部。发电机自动完成的一些事情。

最近几天我一直在找出我愚蠢的错误。有趣的是,当我懒惰时,所有这些都发生了,并决定先构建我的应用程序,然后再进行测试。好吧,我从我的错误中学到了东西。先测试!

相关问题