Reputation: 975
So I am trying to test the simple feature of forgot password.I am newbie, so excuse me if its a silly question. Here, I have to enter user email in forgot_password form which sends me a link in an email to reset password. I am reaching inside the email, but when it clicks the link,page ends up on error page
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
here is my 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
Is there anything I am missing it needs? Thanks!
Upvotes: 1
Views: 286
Reputation: 975
The problem was click_first_link_in_email
. This was not clicking the real link.
I had to use visit_in_email('Reset Password')
to make it open the Reset Password page.
Upvotes: 1