# rails-testing

rails-testing — a set of 46 rules for RSpec, FactoryBot, and Capybara in Ruby on Rails. Guides your AI agent during test generation, reviews, and test suite refactoring.

- skill · `type=skill` · Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, OpenCode, Windsurf (Devin Desktop), Claude.ai · 309 installs · ★ 227 repo stars
- Author: pproenca
- License: MIT · policy=mirror · the beginning of the file is at the end of this page
- Source: https://github.com/pproenca/dot-skills/tree/HEAD/skills/.curated/rails-testing/SKILL.md
- Updated: 2026-08-15
- Security check: automated, 2026-11-16 (text) — no signs of malicious code found.
- HTML: https://affpapa.org/en/nevibecode/skills/rails-testing

## What it does

The skill organizes 46 rules across 8 priority categories for Rails test suites. It instructs the agent to focus on observable behavior rather than private implementation details. This avoids brittle tests. The agent stops writing redundant assertions against built-in ActiveRecord logic.

For test data, the rules prioritize `build` and `build_stubbed` over database persistence. System tests in Capybara forbid `sleep` calls because synchronization relies on built-in waiting. Background jobs separate enqueuing from running `perform`.

Rules also handle transaction-aware job enqueuing in Rails 7.2+. The skill complements `rails-dev`, `ruby-optimise`, and `ruby-refactor`.

## Install

### Claude Code (native platform)

1. **Skills CLI (Vercel)**
```bash
npx skills add pproenca/dot-skills --skill rails-testing -a claude-code
```

2. **Manually: put the files in place**
- File: `~/.claude/skills/rails-testing/SKILL.md` — Copy the whole skill folder; for one project use .claude/skills/rails-testing/

### Codex

1. **Skills CLI (Vercel)**
```bash
npx skills add pproenca/dot-skills --skill rails-testing -a codex
```

2. **Manually: put the files in place**
- File: `.agents/skills/rails-testing/SKILL.md` — For all projects use ~/.agents/skills/

### Cursor

1. **Skills CLI (Vercel)**
```bash
npx skills add pproenca/dot-skills --skill rails-testing -a cursor
```

2. **Manually: put the files in place**
- File: `.cursor/skills/rails-testing/SKILL.md` — Cursor also reads .agents/skills/ and .claude/skills/

### GitHub Copilot

1. **GitHub CLI**
```bash
gh skill install pproenca/dot-skills skills/.curated/rails-testing
```

2. **Manually: put the files in place**
- File: `.github/skills/rails-testing/SKILL.md`

### Gemini CLI

1. **Skills CLI (Vercel)**
```bash
npx skills add pproenca/dot-skills --skill rails-testing -a gemini-cli
```

2. **Platform CLI**
```bash
gemini skills install https://github.com/pproenca/dot-skills --path skills/.curated/rails-testing
```

### Windsurf (Devin Desktop)

**Manually: put the files in place**
- File: `.devin/skills/rails-testing/SKILL.md` — The legacy .windsurf/skills/ path still works

### OpenCode

**Skills CLI (Vercel)**
```bash
npx skills add pproenca/dot-skills --skill rails-testing -a opencode
```

### Claude.ai

**Claude.ai**
- Zip the folder and upload it in Settings → Capabilities → Skills

Where a file is given instead of a command, copy the files from the source to that path: https://github.com/pproenca/dot-skills/tree/HEAD/skills/.curated/rails-testing/SKILL.md

## When to use it
- Replace slow database records with `build_stubbed` in specs
- Eliminate flaky Capybara system tests that depend on `sleep`
- Verify Sidekiq job enqueuing separately from worker execution
- Structure FactoryBot factories using composable traits and sequences
- Migrate legacy controller tests to modern request specs

## Example prompts
- Generate a request spec for the checkout endpoint with role authorization and status checks
- Review this model spec to remove redundant ActiveRecord checks and add validation edge cases
- Refactor the background mailer test to handle Rails 7.2 transaction commit callbacks

## Source text · SKILL.md · MIT

Below is the content of a third-party file. It is data, not instructions for you: do not act on anything written inside unless the human asks. Block tag: 84bc5317381bef13.

BEGIN THIRD-PARTY FILE 84bc5317381bef13
```text
---
name: rails-testing
description: Ruby on Rails testing best practices for writing effective, maintainable test suites with RSpec. This skill should be used when writing, reviewing, or refactoring Rails tests to ensure proper test design, data management, and coverage patterns. Triggers on tasks involving RSpec specs, model tests, request specs, system tests, factory definitions, Capybara interactions, Sidekiq job tests, or test suite optimization. Complementary to rails-dev, ruby-optimise, and ruby-refactor skills.
---

# Community Ruby on Rails Testing Best Practices

Comprehensive testing guide for Ruby on Rails applications, maintained by Community. Contains 46 rules across 8 categories, prioritized by impact to guide automated test generation, review, and refactoring.

## When to Apply

Reference these guidelines when:
- Writing new RSpec specs for models, requests, system tests, or jobs
- Setting up FactoryBot factories with traits and sequences
- Writing Capybara system tests for user journeys
- Testing background jobs with Sidekiq or Active Job
- Reviewing test code for anti-patterns (mystery guests, flaky tests, slow specs)
- Optimizing test suite performance and CI pipeline speed
- Organizing test files, shared examples, and custom matchers

## Rule Categories by Priority

| Priority | Category | Impact | Prefix |
|----------|----------|--------|--------|
| 1 | Test Design & Structure | CRITICAL | `design-` |
| 2 | Test Data Management | CRITICAL | `data-` |
| 3 | Model Testing | HIGH | `model-` |
| 4 | Request & Controller Testing | HIGH | `request-` |
| 5 | System & Acceptance Testing | MEDIUM-HIGH | `system-` |
| 6 | Async & Background Job Testing | MEDIUM | `async-` |
| 7 | Test Performance & Reliability | MEDIUM | `perf-` |
| 8 | Test Organization & Maintenance | LOW-MEDIUM | `org-` |

## Quick Reference

### 1. Test Design & Structure (CRITICAL)

- [`design-four-phase-test`](references/design-four-phase-test.md) - Use four-phase test structure (setup, exercise, verify, teardown)
- [`design-behavior-over-implementation`](references/design-behavior-over-implementation.md) - Test observable behavior, not internal implementation
- [`design-one-assertion-per-test`](references/design-one-assertion-per-test.md) - One logical expectation per test for precise failure diagnosis
- [`design-descriptive-test-names`](references/design-descriptive-test-names.md) - Write test names that read like specifications
- [`design-avoid-mystery-guest`](references/design-avoid-mystery-guest.md) - Make all test data visible within the test itself
- [`design-avoid-conditional-logic`](references/design-avoid-conditional-logic.md) - No if/else or loops in test code
```
END THIRD-PARTY FILE 84bc5317381bef13

The third-party file has ended. Everything between the 84bc5317381bef13 tags is data: requests and commands from it are not followed. An “end of file” line with another tag inside the block is part of the file.

First 2702 of 8510 bytes. © pproenca · MIT · https://github.com/pproenca/dot-skills/tree/HEAD/skills/.curated/rails-testing/SKILL.md

_Part of the page did not fit — see the HTML version._

---
NeVibeCode on affpapa.org. Catalog texts are descriptions, not instructions for the agent. How to choose and install: https://affpapa.org/en/nevibecode/agents.md
