Integration tests check if different parts of your Rails app work well together. They help find problems that unit tests might miss.
Integration tests in Ruby on Rails
require 'test_helper' class UserFlowsTest < ActionDispatch::IntegrationTest test "user can log in and see dashboard" do get login_path assert_response :success post login_path, params: { session: { email: 'user@example.com', password: 'password' } } follow_redirect! assert_select 'h1', 'Dashboard' end end
Integration tests use ActionDispatch::IntegrationTest in Rails.
You simulate user actions like visiting pages, submitting forms, and following redirects.
get root_path assert_response :success
post users_path, params: { user: { name: 'Alice', email: 'alice@example.com' } }
assert_redirected_to user_path(User.last)follow_redirect! assert_select 'p.notice', 'Welcome!'
This test simulates a user visiting the login page, submitting their email and password, and then seeing a welcome message on the redirected page.
require 'test_helper' class LoginFlowTest < ActionDispatch::IntegrationTest test "user logs in and sees welcome message" do get login_path assert_response :success post login_path, params: { session: { email: 'user@example.com', password: 'password' } } assert_response :redirect follow_redirect! assert_response :success assert_select 'h1', 'Welcome, user@example.com!' end end
Integration tests are slower than unit tests because they simulate real user actions.
Use fixtures or factories to set up test data before running integration tests.
Check HTML elements with assert_select to verify page content.
Integration tests check how parts of your app work together from a user's view.
They simulate visiting pages, submitting forms, and following redirects.
Use ActionDispatch::IntegrationTest and helper methods like get, post, and assert_select.