0
votes

During an rspec-test, I am attempting to reset my password by filling a form and clicking the "Reset Password" link.

Capybara gives me the following error:

1) ResetPasswords emails user a reset link when resetting password
   Failure/Error: click_link 'Reset Password'
   Capybara::ElementNotFound:
     Unable to find link "Reset Password"

Apparently it does not find the link I want it to click. But when I attempt to print the page on which it is looking with puts page.body, this element is present:

<div><input name="commit" type="submit" value="Reset Password" /></div>

I've attempted to use click, click_button and click_link, but no cigar.

Why is the element not being found?

Update 1: click_button output

1) ResetPasswords emails user a reset link when resetting password
   Failure/Error: click_button 'Reset Password'
   ActionView::Template::Error:
     Missing host to link to! Please provide the :host parameter, set
     default_url_options[:host], or set :only_path to true

Update 2: Test file

require 'spec_helper'

include Warden::Test::Helpers
Warden.test_mode!

describe "ResetPasswords" do
  it "emails user a reset link when resetting password" do
    visit login_path
    click_link 'password'

    fill_in 'Email', :with => @user.email

    puts page.body
    click_link 'Reset Password'

    page.should have_content "You will receive an email"
  end

  before(:each) do
    @user = create(:user)
    #login_as @user, :scope => :user
  end
end
2
What is the output given by click_button 'Reset Password' method?Ashish Bista
Please see the updated post.krystah
As you can see, it finds the Email field and fills it properly, I have confirmed this. Yet, it does not know how to submit the form..krystah

2 Answers

1
votes

Putting this snippet into config/environments/test.rb solved it:

config.action_mailer.default_url_options = {:host => "localhost:3000"}
0
votes

try going directly to page for reset password

describe "ResetPasswords" do
  it "emails user a reset link when resetting password" do
    visit reset_password_path

    fill_in 'Email', :with => @user.email

    click_link 'Reset Password'

    page.should have_content "You will receive an email"
  end

  before(:each) do
    @user = create(:user)
    #login_as @user, :scope => :user
  end
end