使用rspec,capybara和email_spec进行设计密码恢复的集成测试

时间:2013-03-03 09:46:33

标签: ruby-on-rails rspec devise capybara email-spec

我正在尝试使用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。

任何人都可以指出我正确的方向吗?非常感谢。

1 个答案:

答案 0 :(得分:3)

/config/environments/test.rb

中设置以下行
config.action_mailer.default_url_options = { :host => 'localhost:3000' }