我不知道爲什麼它不起作用。經過幾個小時的試圖弄清楚這一點,我寫了一個小測試來檢查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%確定那是固定的。 –