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 回答