Last active
September 13, 2023 17:41
-
-
Save alexshapalov/649f3de38ed845731353aca3d00fef9f to your computer and use it in GitHub Desktop.
Shared example in Rails with RSpec and 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
# 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