Guide

Follow the chapters in order with the Recipes app. From your first test through models, system tests, auth, jobs, and CI.

Introduction to Minitest Rails Guide

Why the Minitest Rails guide exists, who it's for (beginners and experienced alike), 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.

Types of tests in the Rails world

How model, controller, integration, and system tests fit together in Minitest, where they live under test/, and when to pick each for the Recipes app.

Testing tools in the Minitest world

Minitest, fixtures, Capybara, and when something like WebMock or VCR earns a place.

How to approach testing

Build scenarios in plain language, manual checks in the reference Recipes app, and practice drills with hidden example answers. No automated tests in this chapter.

Your first test

Scenario first, then code: Recipe scaffold, a model test that fails then passes, first HTTP integration tests (list + create), one system smoke test, and how to read passing output.

Test data - fixtures

YAML fixtures, associations, and keeping data predictable so later tests do not fight random state.

Testing simple CRUD (system tests)

Drive the browser through list, show, create, update, and delete for Recipes using the fixture data you set up earlier. System tests for CRUD with remaining integration tests for update and destroy.

Testing models

Validations, scopes and methods. What to test and when.

A second resource and associations

Grow Recipes with nested resources, fixture associations for ingredients and steps, and tests that follow the same scenario-first habit from Chapter 4.

Request and controller tests

When request or controller tests earn their keep instead of pushing everything through a time consuming system test.

Testing authentication

Rails built-in authentication in the Recipes app: sign in, sign out, session helpers in tests, and wiring recipes to users before authorization rules.

Authorization testing

Who can hit which actions, ownership rules, signed-in vs guest, and redirects when someone is not allowed.

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.

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.

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.

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.

Support via Stripe

Missing a topic?

Tell us what you'd like covered and we'll consider adding a chapter.

Suggest a topic