Rails Implementation Guide

Testing Rails in Practice

Know what to test in a Rails app and where to test it.

Follow one Rails app through Minitest and RSpec examples. See when a model test is enough, what to check in a request test, and when a browser is worth the extra setup.

Read a free chapter

In final editing · 10 chapters · Rails 8.1 · Agent Companion

Not on sale yet. It joins the Developer Library when it’s finished.

Testing Rails in Practice by Rob Race. Two passing test marks follow different paths toward a boundary.
Choose the right testing boundary,
protect behavior, and keep the suite useful

What does a passing test actually prove?

Suppose a regular member tries to change an admin’s role. A test that only checks for a 403 can pass even if the app changes the role before denying the request. Chapter 4 shows how to test the whole denial.

Read Chapter 4 →
Response
The app returns 403.
Database
The admin keeps their role.
Job queue
No role-change email is queued.

Inside the guide

  1. What Are You Actually Protecting?

    Name the behavior someone relies on before deciding what to test.

  2. Pick the Cheapest Useful Boundary

    Choose between model, request, job, and browser tests based on what can break.

  3. Test Behavior, Not Implementation

    Use assertions that catch regressions and survive harmless refactors.

  4. Requests, Authentication, Authorization, and Tenancy

    Prove a denial leaves protected data and side effects alone.

  5. Models, Services, and Domain Work

    Check invariants and prove that an operation really rolls back.

  6. External Systems Without Lying to Yourself

    Stub transport failures and check the request your client actually sends.

  7. Testing Background Work

    Test enqueueing, execution, and recovery at their own boundaries.

  8. Use a Browser When You Need a Browser

    Use real sessions to test Turbo frames and tenant-scoped streams.

  9. Test Data, Helpers, and Maintainability

    Build fixtures or factories that make the important relationships visible.

  10. A Test Suite You Can Live With

    Audit an existing suite for proof, maintenance cost, and missing coverage.

The guide and its companion

The book

Ten chapters in PDF, EPUB, and HTML, with paired Minitest and RSpec examples.

Executable examples

Two Rails apps exercise the same behavior and back the guide’s weak-versus-strong test comparisons.

Agent Companion

Contracts, recipes, and review checklists for testing a change or auditing an existing suite.

Start with request tests

Read the complete chapter on authentication, authorization, and tenancy, including the paired examples.