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’」在該文件的頂部。發電機自動完成的一些事情。

最近幾天我一直在找出我愚蠢的錯誤。有趣的是,當我懶惰時,所有這些都發生了,並決定先構建我的應用程序,然後再進行測試。好吧,我從我的錯誤中學到了東西。先測試!

相關問題