Guide
Introduction
Why this guide exists, who it's for, and how the Recipes app grows with you.
Setting up the Recipe app
Spin up the Recipes app with the Rails default with one addition: system tests which has been removed from defaults from Rails 8. Enough Capybara wiring to follow later chapters.
Kinds of Rails tests (and when to use each)
How unit (model), integration (request), and system (browser) tests differ in Minitest land, and when each is a good fit.
How to approach testing
A simple loop when you feel stuck: what you would check by hand, what you are actually varying in the test, and how you will know it passed. Now automate all of that with Minitest.
Testing tools in the Minitest world
Minitest, fixtures, Capybara, and when something like WebMock or VCR earns a place.
Your first test
One small green test in the real app so you practice running the suite and trusting a passing run.
Test data - fixtures
YAML fixtures, associations, and keeping data predictable so later tests do not fight random state.
Testing a simple CRUD (system tests)
Drive the browser through list, show, create, update, and delete for Recipes using the fixture data you set up earlier.
Testing models
Validations, scopes and methods. What to test and when.
Doubles and stubs in Minitest
What doubles and stubs buy you in Minitest, how Object#stub and Minitest::Mock stand in for real collaborators in-process, and when each is a good fit so tests stay readable without mocking the whole world.
A second resource and associations
Grow Recipes with nested resources, more system and model tests, and nested params without losing the thread of one app.
Request/controller tests (when to use them)
When request or controller tests earn their keep instead of pushing everything through a time consuming system test.
Authorization testing
Who can hit which actions, signed-in and signed-out flows, ownership, and redirects.
Testing mailers
Keep mailers thin, assert on body and delivery, use fixtures for related records, and stub only when the scenario really needs it.
Testing background jobs
Exercise enqueue and perform paths, keep jobs thin.
Mock external services
Stub and record HTTP with WebMock and VCR so tests don't hit the real network and stay deterministic in CI.
Adding tests to an existing project
A practical order of attack when the codebase already exists: align on goals, start where tests are easiest to add, then widen coverage.
Test coverage and when to test more
Why there is no magic percentage, and which team pains usually mean you need more tests (bugs, fear of deploy, manual regression, refactor paralysis).
Habits and TDD
Building a routine around tests, when test-first actually helps, and when writing tests after is fine.
Running tests in CI
Run the same suite in GitHub Actions or similar CI: databases, env vars, headless browsers for system tests, and keeping the pipeline boring and reliable.
Finish
Wrap up the Recipes journey, what you practiced across the chapters in this guide, and where to take your testing next.