2

email_spec を使用して rspec/capybara を使用してパスワードの回復をテストしようとしています

私のtest.rbには以下が含まれています:

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 についてはよくわかりません。

誰でも私を正しい方向に向けることができますか? どうもありがとう。

4

1 に答える 1

3

に次の行を設定します/config/environments/test.rb

config.action_mailer.default_url_options = { :host => 'localhost:3000' }
于 2013-05-29T19:17:56.367 に答える