Skip to content

Instantly share code, notes, and snippets.

@scmx
Created January 28, 2015 16:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scmx/8d07e3acb09dd9a092ec to your computer and use it in GitHub Desktop.
Save scmx/8d07e3acb09dd9a092ec to your computer and use it in GitHub Desktop.
#TIL #capybara #save_and_open_page #pry

Today I learned that when using a binding.pry like this inside a Capybara feature test

require "test_helper"

feature "User::CanResetPassword" do
  before do
    visit reset_password_path
  end

  scenario "valid email" do
    binding.pry
    within("form[action='/password_resets']") do
      fill_in "Email", with: "admin@example.com"
    end
    click_button "Submit"
    current_path.must_equal sent_password_path
  end

you can use the following method

pry(#<User::CanResetPassword Feature Test>)> save_and_open_page

This opens the page content in a browser. Which makes it easier to debug if the selector you think should match something doesn't match anything.

Source: http://www.stefanwille.com/2010/12/printing-the-page-content-in-capybara/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment