Guide
Follow the chapters in order with the Cookbook app. From your first test through models, system tests, auth, jobs, and CI.
Introduction to Minitest Rails testing guide
Who this free Minitest Rails guide is for, and how it teaches Rails testing while sticking to the Rails defaults.
Setting up Minitest in Rails
Generate a Rails app with Minitest, enable system tests after Rails 8 defaults, and get a green suite with Capybara.
Types of tests in Rails
How model, controller, integration, and system tests fit together in Minitest, and when to pick each.
Testing tools for Minitest in Rails
Minitest, fixtures, Capybara, and when WebMock or VCR earns a place in a Rails test suite.
How to approach testing
Write scenarios in plain language, practice manual checks, and build a habit before you automate with Minitest.
Your first test
Write your first Rails Minitest model test, integration tests for list and create, and one system smoke test.
Rails fixtures for Minitest
Use YAML fixtures in Rails so Minitest suites start from predictable data instead of random setup.
Testing CRUD with system tests in Rails
Drive list, show, create, update, and delete in the browser with Capybara, and keep integration tests for update and destroy.
Testing Rails models with Minitest
Test validations, scopes, and model methods in Minitest, and know what belongs in a model test.
Testing nested resources and associations in Rails
Test nested resources, associations, and nested forms over HTTP with Minitest.
Testing dynamic forms in Rails
Test Stimulus-powered nested form fields in Rails with system and integration tests.
Testing Turbo Frames and Streams
Test Turbo Frames and Streams in Rails with Minitest by asserting outcomes, not Turbo markup.
Testing authentication in Rails
Test Rails 8 built-in authentication with Minitest: sign in, sign out, guest read-only access, and password reset.
Authorization testing in Rails
Test ownership and authorization in Rails with Minitest: who can edit, and who gets redirected.
Testing mailers in Rails
Test Action Mailer with Minitest: assert on content, delivery, and when stubbing helps.
Testing background jobs in Rails
Test Active Job enqueue and perform paths in Minitest without duplicating every assertion.
Testing JSON APIs in Rails
Test Rails JSON APIs with Minitest using status codes and parsed response bodies.
Doubles and stubs in Minitest
Use Object#stub and Minitest::Mock for in-process collaborators, and know when each fit keeps tests readable.
Mock external services with WebMock and VCR
Stub and record HTTP with WebMock and VCR so Rails tests stay off the real network and deterministic in CI.
Adding tests to an existing Rails project
A practical order of attack for legacy Rails apps: align on goals, start where tests are easiest, then widen coverage.
Test coverage and when to test more
Why there is no magic coverage percentage, and which team pains usually mean you need more Rails tests.
TDD habits for Rails with Minitest
Build a testing routine in Rails, when test-first helps, and when writing tests after is fine.
Running Rails tests in CI
Run Minitest in GitHub Actions: databases, env vars, headless browsers for system tests, and a reliable pipeline.
Next steps after learning Rails testing
What you practiced across this Minitest Rails guide, and where to take your testing next.
This guide stays free. Forever.
You have the full chapter list in front of you. Support does not unlock any new content. But it funds new chapters, Rails updates, and better examples while keeping everything free to read.
Missing a topic?
Tell us what you'd like covered and we'll consider adding a chapter.