Guide
Introduction
Why this guide exists, who it's for, and how the Recipes app grows with you.
Setting up a Rails app with Minitest
New app with Minitest, Capybara, and enough to run tests.
Kinds of Rails tests (and when to use each)
Unit, integration, and system tests with Minitest.
How to approach testing
Plan, parameters, and result—a repeatable way to think about any test.
Testing tools in the Minitest world
Minitest, fixtures, Capybara, WebMock/VCR; stick to defaults.
Your first test
One passing test in the Recipes app; run tests, see green.
Testing a simple CRUD (system tests)
System tests for list, show, create, update, delete (Recipes).
Testing models
Validations, custom methods, scopes; keep controllers thin.
Test data - fixtures
Fixtures (YAML, ERB), associations, deterministic tests.
Stubs, mocks and doubles (when to use them)
Minitest::Mock, stubs, mocks; when to use and when not to.
A second resource and associations
Ingredients and steps under Recipe; nested CRUD, system and model tests.
Request/controller tests (when to use them)
When to use request tests; API-only, legacy controllers, Minitest style.
Authorization testing
Testing who can do what—ownership, roles, unauthenticated redirects.
Testing mailers
Keep mailers thin; test delivery and content. Example: Share this recipe.
Testing background jobs
Keep jobs thin; test enqueue/perform and the code they call.
Testing with external services
WebMock, VCR; deterministic tests; when to stub vs record; CI.
Adding tests to an existing project
Shared vision, start with easiest CRUD, then expand.
Test coverage and when to test more
No magic number; pains that suggest you need more tests.
Habits and TDD
Making testing habitual; TDD as optional; when to write tests first.
Running tests in CI
GitHub Actions, GitLab CI; test DB, env vars, headless system tests.
Finish
What we built (Recipes app), what we learned, where to go next.