0
0
Ruby on Railsframework~30 mins

System tests with Capybara in Ruby on Rails - Mini Project: Build & Apply

Choose your learning style9 modes available
System tests with Capybara
📖 Scenario: You are building a simple blog application in Rails. You want to make sure that users can visit the homepage and see the welcome message correctly.
🎯 Goal: Create a system test using Capybara that visits the homepage and checks for the presence of the welcome text.
📋 What You'll Learn
Create a system test file for the homepage
Set up Capybara to visit the root path
Write a test that checks for the welcome message text
Run the test to verify it passes
💡 Why This Matters
🌍 Real World
System tests help ensure your web app works correctly from the user's point of view by simulating real browser actions.
💼 Career
Knowing how to write system tests with Capybara is valuable for Rails developers to maintain high-quality, reliable applications.
Progress0 / 4 steps
1
Create the system test file
Create a system test file called home_page_test.rb inside test/system/ folder with a class HomePageTest that inherits from ApplicationSystemTestCase.
Ruby on Rails
Need a hint?

This file sets up the system test class where you will write your tests.

2
Add a test method to visit the homepage
Inside the HomePageTest class, add a test method called test_visiting_homepage that uses visit root_path to open the homepage.
Ruby on Rails
Need a hint?

The visit method tells Capybara to open the page at the given path.

3
Check for the welcome message on the homepage
Inside the test_visiting_homepage method, add an assertion using assert_text "Welcome to the Blog!" to verify the welcome message is visible.
Ruby on Rails
Need a hint?

The assert_text method checks if the given text appears anywhere on the page.

4
Run the system test
Run the system test by executing bin/rails test:system test/system/home_page_test.rb in your terminal to verify the test passes.
Ruby on Rails
Need a hint?

Use the Rails command line to run system tests and see the results.