0
0
Ruby on Railsframework~30 mins

Integration tests in Ruby on Rails - Mini Project: Build & Apply

Choose your learning style9 modes available
Integration Tests in Rails
📖 Scenario: You are building a simple blog application in Rails. You want to make sure that users can visit the homepage and see the list of posts correctly.
🎯 Goal: Create an integration test that visits the homepage and checks that the page shows the title of a post.
📋 What You'll Learn
Create a post record with a specific title
Set up a test to visit the homepage path
Check that the page contains the post title text
Use Rails integration test syntax with get and assert_select
💡 Why This Matters
🌍 Real World
Integration tests help ensure that different parts of a web app work together correctly, like visiting pages and seeing expected content.
💼 Career
Rails developers use integration tests to catch bugs early and maintain app quality, which is important for professional web development.
Progress0 / 4 steps
1
Create a post record
Create a post record with the title 'My First Post' using Post.create! and assign it to a variable called post.
Ruby on Rails
Need a hint?

Use Post.create!(title: 'My First Post') and assign it to post.

2
Set up the integration test class
Create a class called PostsFlowTest that inherits from ActionDispatch::IntegrationTest.
Ruby on Rails
Need a hint?

Use class PostsFlowTest < ActionDispatch::IntegrationTest to start the test class.

3
Write a test method to visit homepage
Inside the PostsFlowTest class, write a test method called test_visiting_homepage that uses get root_path to visit the homepage.
Ruby on Rails
Need a hint?

Define def test_visiting_homepage and call get root_path inside it.

4
Assert the post title appears on the page
Inside the test_visiting_homepage method, add an assert_select that checks for an h1 element containing the text 'My First Post'.
Ruby on Rails
Need a hint?

Use assert_select 'h1', 'My First Post' to check the page content.