2013-03-03 226 views
2

我試圖使用使用email_spec集成測試

我test.rb RSpec的/水豚測試密碼恢復包含:

config.action_mailer.delivery_method = :test 

我的測試去像這樣:

feature User do 
    let!(:user){ FactoryGirl.build(:user) } 

    before(:each) do 
    visit root_path 
    click_link "Sign up/in" 
    end 

    scenario "recover password" do 
    user.save! 
    click_link "Forgot password?" 
    fill_in "Email", :with => user.email 
    click_button "Send me reset password instructions" 
    unread_emails_for(user.email).should be_present 
    end 

我的測試失敗,像這樣:

1) User recover password 
    Failure/Error: click_button "Send me reset password instructions" 
    ActionView::Template::Error: 
     Missing host to link to! Please provide the :host parameter, 
     set default_url_options[:host], or set :only_path to true 

如果我設置了default_url_options,rspec會嘗試發送郵件。我不太確定:only_path。

任何人都可以請指出我在正確的方向嗎?非常感謝。

+0

http://stackoverflow.com/questions/7284413/how-to-test-with-rspec-if-an-email-is-delivered-由這控制器 – apneadiving 2013-03-03 13:23:51

回答

3

坐落在/config/environments/test.rb以下行:

config.action_mailer.default_url_options = { :host => 'localhost:3000' }