Skip to content

Instantly share code, notes, and snippets.

@alexshapalov
Last active September 13, 2023 17:41
Show Gist options
  • Save alexshapalov/649f3de38ed845731353aca3d00fef9f to your computer and use it in GitHub Desktop.
Save alexshapalov/649f3de38ed845731353aca3d00fef9f to your computer and use it in GitHub Desktop.
Shared example in Rails with RSpec and Capybara
# Shared stuff for logging in
RSpec.shared_context 'logged in user' do
before do
visit '/login'
fill_in 'username', with: 'test_user'
fill_in 'password', with: 'test_password'
click_button 'Login'
end
end
# Actual tests
RSpec.describe 'My Feature' do
include_context 'logged in user'
it 'checks out feature A' do
visit '/feature_A'
expect(page).to have_content('Welcome to Feature A')
end
it 'checks out feature B' do
visit '/feature_B'
expect(page).to have_content('Welcome to Feature B')
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment