Skip to content

Instantly share code, notes, and snippets.

@spencerldixon
Last active August 28, 2020 12:01
Show Gist options
  • Save spencerldixon/004c0e052563b833d46f3b63139ce872 to your computer and use it in GitHub Desktop.
Save spencerldixon/004c0e052563b833d46f3b63139ce872 to your computer and use it in GitHub Desktop.
Capybara feature specs for a simple Devise installation
require 'rails_helper'
RSpec.feature 'User Registration', type: :feature do
let(:new_user) { FactoryBot.build(:user) }
let(:user) { FactoryBot.create(:user) }
scenario 'User can sign up' do
visit root_path
first(:link, 'Sign up').click
fill_in 'First name', with: new_user.first_name
fill_in 'Last name', with: new_user.last_name
fill_in 'Email', with: new_user.email
fill_in 'Password', with: new_user.password
fill_in 'Password confirmation', with: new_user.password
click_button 'Sign up'
expect(page).to have_text('You have signed up successfully')
expect(page).to have_text("Hello #{new_user.first_name}!")
end
scenario 'User can sign in' do
visit root_path
click_on 'Log in'
fill_in 'Email', with: user.email
fill_in 'Password', with: user.password
click_button 'Log in'
expect(page).to have_text('Signed in successfully')
expect(page).to have_text("Hello #{user.first_name}!")
end
scenario 'User can sign out' do
sign_in user
visit root_path
expect(page).to have_text("Hello #{user.first_name}!")
click_on "Hello #{user.first_name}"
click_on 'Sign Out'
expect(page).to have_text('Signed out successfully')
expect(page).to_not have_text("Hello #{user.first_name}!")
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment