skills/rails-testing-patterns/SKILL.md
Analyzes Rails test suites and recommends testing best practices for RSpec and Minitest. Use when writing new tests, reviewing test coverage, fixing flaky tests, improving test performance, choosing between test types (unit, integration, system, request), or setting up factories and fixtures. NOT for production monitoring, deployment verification, or load/stress testing infrastructure.
npx skillsauth add ag0os/rails-dev-plugin rails-testing-patternsInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Use standard RSpec and Minitest conventions for syntax, assertions, matchers, and Capybara DSL. This skill focuses on opinionated choices — what to test, which framework to use, and how to structure test data.
See patterns.md for decision guidance and non-obvious patterns.
| Test Type | When to Write | Speed | ROI Notes |
|-----------|--------------|-------|-----------|
| Unit (Model) | Business logic, validations, scopes, custom methods | Fast | Highest ROI — write first wherever models or services carry non-trivial logic |
| Request | API endpoints, auth flows, param handling | Medium | Highest ROI on the api delivery axis; prefer over controller specs in RSpec |
| Integration | Multi-step workflows spanning controllers | Medium | Valuable on the html delivery axis — exercises the full request/render cycle |
| System | Critical user journeys only (sign-up, checkout, onboarding) | Slow | Limit to 10-20 per app; never test CRUD forms with system tests |
| Mailer | Non-trivial email content, conditional delivery | Fast | Skip if mailer is just a default scaffold |
| Job | Idempotency, retry behavior, side effects | Fast | Always test jobs that touch external services |
Test framework, data strategy, and directory are orthogonal project facts, not architecture choices. A project with extracted service objects can use Minitest; an omakase app can use RSpec. Read them from the project-conventions fingerprint (Testing category) — framework (Minitest/RSpec), data (fixtures/factories), directory (test/ vs spec/). Never infer the framework from architecture.
Test emphasis does vary by Axis B — delivery:
| Delivery | First tests to write | System tests |
|----------|---------------------|--------------|
| html | Integration tests for key flows | Yes, for critical user journeys |
| api | Request specs | No — request specs cover it |
| Anti-Pattern | Do Instead | Why |
|-------------|-----------|-----|
| Testing Rails internals (validates_presence_of works?) | Test your domain logic only | Rails is already tested |
| sleep in system tests | Rely on Capybara's built-in waiting (have_content, assert_text) | Sleep is flaky and slow |
| Shared mutable state between tests | Fresh state per test via let/setup | Test ordering bugs are the hardest to debug |
| Testing private methods directly | Test through the public interface | Couples tests to implementation |
| Huge factory/fixture with every field | Minimal defaults + traits/overrides | Reduces test fragility and speeds diagnosis |
| System tests for CRUD forms | Request/integration tests | 10x faster, same coverage for form submissions |
| Mocking the object under test | Mock collaborators, not the subject | Tests nothing useful |
Use whichever strategy the project already uses — the project-conventions fingerprint reports fixtures vs factories. Guidance for each:
When the project uses fixtures:
jane:, admin: — never user_1:, user_2:Model.new(...) only for one-off edge cases not worth a fixtureWhen the project uses factories:
build (not create) whenever persistence isn't needed — dramatically fastersequence for uniqueness constraints (emails, slugs)create chains — if a test needs 4+ create calls, consider fixtures for that scenarioWhen reporting on test quality, use:
## Test Analysis: [spec_or_test_file]
**Coverage Gaps:**
- [model/action] missing test for [scenario]
**Issues:**
- [severity] description
**Recommendations:**
1. actionable recommendation
development
WHAT: Language-agnostic corrective guidance for the refactoring phase. WHEN: Agent is restructuring code, fixing code smells, reducing complexity, or improving maintainability. NOT FOR: Writing new features, debugging runtime errors, performance tuning, or object design decisions.
tools
Analyzes Rails view templates, partials, layouts, helpers, and form patterns for best practices. Use when reviewing ERB templates, improving view performance with fragment caching, fixing form helpers, organizing partials, adding accessibility attributes, or evaluating collection rendering. NOT for Stimulus/Turbo logic (use hotwire-patterns), controller concerns, or API-only responses.
development
Detects a Rails project's architecture axes — logic placement (native vs extracted) and delivery (html vs api) — so other skills load profile-appropriate guidance without inline conditionals. Use when planning architecture or when a recommendation depends on where business logic lives or whether the app renders HTML or serves JSON. NOT for test framework, job backend, cache store, or auth library choices — those are orthogonal facts detected by project-conventions.
data-ai
Action Mailer patterns for Rails applications. Automatically invoked when working with email delivery, mailer classes, email templates, mailer previews, interceptors, or delivery configuration. Triggers on "mailer", "email", "ActionMailer", "deliver_later", "deliver_now", "mail template", "email preview", "SMTP", "SendGrid", "Postmark", "notification email". NOT for push notifications, SMS, or in-app messaging.