Guide

0

Introduction

Why this guide exists, who it's for, and how the Recipes app grows with you.

1

Setting up a Rails app with Minitest

New app with Minitest, Capybara, and enough to run tests.

2

Kinds of Rails tests (and when to use each)

Unit, integration, and system tests with Minitest.

3

How to approach testing

Plan, parameters, and result—a repeatable way to think about any test.

4

Testing tools in the Minitest world

Minitest, fixtures, Capybara, WebMock/VCR; stick to defaults.

5

Your first test

One passing test in the Recipes app; run tests, see green.

6

Testing a simple CRUD (system tests)

System tests for list, show, create, update, delete (Recipes).

7

Testing models

Validations, custom methods, scopes; keep controllers thin.

8

Test data - fixtures

Fixtures (YAML, ERB), associations, deterministic tests.

9

Stubs, mocks and doubles (when to use them)

Minitest::Mock, stubs, mocks; when to use and when not to.

10

A second resource and associations

Ingredients and steps under Recipe; nested CRUD, system and model tests.

11

Request/controller tests (when to use them)

When to use request tests; API-only, legacy controllers, Minitest style.

12

Authorization testing

Testing who can do what—ownership, roles, unauthenticated redirects.

13

Testing mailers

Keep mailers thin; test delivery and content. Example: Share this recipe.

14

Testing background jobs

Keep jobs thin; test enqueue/perform and the code they call.

15

Testing with external services

WebMock, VCR; deterministic tests; when to stub vs record; CI.

16

Adding tests to an existing project

Shared vision, start with easiest CRUD, then expand.

17

Test coverage and when to test more

No magic number; pains that suggest you need more tests.

18

Habits and TDD

Making testing habitual; TDD as optional; when to write tests first.

19

Running tests in CI

GitHub Actions, GitLab CI; test DB, env vars, headless system tests.

20

Finish

What we built (Recipes app), what we learned, where to go next.