felixandrea
Joined
10 Experience
0 Lessons Completed
0 Questions Solved
Activity
To test the order of elements on a page with Rspec and Capybara, you can do the following:
- Create a new Rspec test to check the display order of the teams: # spec/features/team_index_spec.rb require 'rails_helper'
RSpec.describe 'Team Index Page', type: :feature do
it 'displays teams in the correct order' do
# Create some teams with different creation dates
team1 = create(:team, created_at: 1.day.ago)
team2 = create(:team, created_at: Time.now)
# Visit the team index page
visit teams_path
# Check the display order of the teams
expect(page).to have_selector('div.team', count: 2)
expect(page.all('div.team')[0]).to have_content(team2.name)
expect(page.all('div.team')[1]).to have_content(team1.name)
end
end
- In the test above:
- Create two teams with different creation dates
- Visit the team index page
- Check that the page displays the correct 2 teams
Check that the newly created team is displayed before the older one
Run this test with rspec spec/features/team_index_spec.rb. If the test passes, it means the display order of the teams on the page is as expected.
I hope these instructions help you test the order of elements on a Rails app page with Rspec and Capybara.