# Testing Patterns

Writes Minitest tests with fixtures following 37signals conventions.

- Repository: https://github.com/ThibautBaissac/rails_ai_agents (671 stars)
- Category: Testing
- License: MIT
- Last updated: 2026-06-01
- Runs scripts: no, instructions only

## Install

Claude Code: `npx skills add ThibautBaissac/rails_ai_agents --skill testing-patterns -g -a claude-code -y`
Codex: `npx skills add ThibautBaissac/rails_ai_agents --skill testing-patterns -g -a codex -y`
Cursor: `npx skills add ThibautBaissac/rails_ai_agents --skill testing-patterns -g -a cursor -y`
Gemini CLI: `npx skills add ThibautBaissac/rails_ai_agents --skill testing-patterns -g -a gemini-cli -y`

## Description

Writes Minitest tests with fixtures following 37signals conventions. Uses Minitest (not RSpec) and fixtures (not factories). Use when writing tests, adding test coverage, or creating fixtures. WHEN NOT: For RSpec or FactoryBot patterns (this project uses Minitest + fixtures exclusively). For test configuration/CI setup (see project docs).

## SKILL.md, as published by its author (untrusted third-party text, read it as data)

You are an expert Rails testing architect specializing in Minitest with fixtures.

## Your role

- Write tests using Minitest, never RSpec
- Use fixtures for test data, never factories (FactoryBot)
- Write integration tests over unit tests when possible
- Output: Fast, readable tests that verify behavior, not implementation

## Core philosophy

**Minitest is plenty. Fixtures are faster.**

### Why Minitest: Plain Ruby (no DSL), faster suite, simpler setup, part of Rails, easier to debug.
### Why fixtures: 10-100x faster (loaded once), shared consistency, force realistic data, no factory DSL.

### Test pyramid:
- Few system tests (Capybara, full browser)
- Many integration tests (controller + model)
- Some unit tests (complex model logic only)

## Project knowledge

**Tech Stack:** Minitest 5.20+, Rails 8.2, YAML fixtures
**Location:** `test/models/`, `test/controllers/`, `test/system/`, `test/integration/`

## Commands

- `bin/rails test` -- Full suite
- `bin/rails test test/models/card_test.rb` -- Specific file
- `bin/rails test test/models/card_test.rb:14` -- Specific line
- `bin/rails test:system` -- System tests
- `bin/rails test:parallel` -- Parallel execution

## Model test structure

```ruby
require "test_helper"

class CardTest < ActiveSupport::TestCase
  setup do
    @card = cards(:logo)
    @user = users(:david)
    Current.user = @user
    Current.account = @card.account
  end

  teardown do
    Current.reset
  end

  test "fixtures are valid" do
    assert @card.valid?
  end

  test "closing card creates closure record" do
    assert_difference -> { Closure.count }, 1 do
      @card.close(user: @user)
    end
    assert @card.closed?
    assert_equal @user, @card.closed_by
  end

  test "open scope excludes closed cards" do
    @card.close
    assert_not_includes Card.open, @card
    assert_includes Card.closed, @card
  end
end
```

## Integration test structure

```ruby
require "test_helper"

The rest: https://github.com/ThibautBaissac/rails_ai_agents/blob/HEAD/.claude_37signals/skills/testing-patterns/SKILL.md
