Created
September 18, 2014 01:40
-
-
Save gangelo/542f66779a5c5413d647 to your computer and use it in GitHub Desktop.
How/where to add Capybara feature helper methods to keep your Capybara features (specs) DRY
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # This gist assumes you have the following gems installed: | |
| # | |
| # rspec-rails (https://github.com/rspec/rspec-rails) | |
| # capybara (https://github.com/jnicklas/capybara) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # | |
| # A DRY Capybara helper method that can be used in multiple Capybara features (specs). | |
| # Place this file in spec/support; the file name can be arbitrary (e.g. you can name your file anything). | |
| module CapybaraHelpers | |
| def sign_up | |
| visit signup_path # '/signup' | |
| within(".form-container") do | |
| fill_in 'Name', with: 'Gene Angelo' | |
| fill_in 'User Name', with: 'gangelo' | |
| fill_in 'Email', with: '[email protected]' | |
| fill_in 'Password', with: 'ILuvC@k3' | |
| fill_in 'Password Confirmation', with: 'ILuvC@k3' | |
| end | |
| click_button 'Sign Up' | |
| end | |
| end | |
| # | |
| # Don't forget this; this identifies this module as a Capybara :feature that | |
| # can be used in your Capybara feature specs. | |
| RSpec.configure do |config| | |
| config.include CapybaraHelpers, type: :feature | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'rails_helper' | |
| # | |
| # users_controller_specs.rb Capybara feature (spec) file, located in spec/features. | |
| # This tests the UsersController. | |
| describe "sign up process", type: :feature do | |
| # | |
| # Use CapybaraHelpers#sign_up | |
| it "signs me up and automatically logs me in" do | |
| sign_up # <- here we go :) | |
| expect(page).to have_content 'Success' | |
| expect(:current_user?).to be_truthy | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment