1

所以我正在尝试测试忘记密码的简单功能。我是新手,如果这是一个愚蠢的问题,请原谅。在这里,我必须以 forgot_password 形式输入用户电子邮件,它会在电子邮件中向我发送一个链接以重置密码。我正在访问电子邮件,但是当它单击链接时,页面最终出现在错误页面上

在此处输入图像描述

 it "sends reset password email on submit",:js=> true, :focus=>true do


    visit "/login"
    click_link "Forgot Password?"
    sleep 1
    fill_in "email", :with => @user.email
    click_button "Submit"
    email = open_email(@user.email)
    email.should deliver_to(@user.email)
    #email.should have_subject("FlinkMusic - Forgot you password")
    click_first_link_in_email

    page.should have_content ("Reset your password")
        fill_in "Password ", :with => "password1" 
        fill_in "Repeat Password", :with => "password1"
        click_button "Reset Password"
        page.should have_content "Your password has been reset.Please log in."

end

这是我的 spec_helper

   require 'rubygems'
   require 'spork'
   Spork.prefork do

   ENV["RAILS_ENV"] ||= 'test'
   require File.expand_path("../../config/environment", __FILE__)
   require 'rspec/rails'
  require 'rspec/autorun'
  require 'capybara/rspec'
  require "capybara-screenshot"
  require 'factory_girl_rails'
  Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}

 #Capybara.defualt_wait_time = 10

  if ENV['BROWSER_TEST']
Capybara.register_driver :selenium do |app|
Capybara::Selenium::Driver.new(app, :browser => :chrome)
 end
else
Capybara.javascript_driver = :selenium
 end
RSpec.configure do |config|

      config.include Capybara::DSL

     config.include(EmailSpec::Helpers)
     config.include(EmailSpec::Matchers)


     config.treat_symbols_as_metadata_keys_with_true_values = true
     config.filter_run :focus => true
     config.run_all_when_everything_filtered = true

有什么我想念的吗?谢谢!

4

1 回答 1

1

问题是click_first_link_in_email。这不是点击真正的链接。我不得不使用visit_in_email('Reset Password')它来打开重置密码页面。

于 2013-11-25T20:39:31.210 回答