install
source · Clone the upstream repo
git clone https://github.com/ComeOnOliver/skillshub
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/ComeOnOliver/skillshub "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/pproenca/dot-skills/rails-testing" ~/.claude/skills/comeonoliver-skillshub-rails-testing && rm -rf "$T"
manifest:
skills/pproenca/dot-skills/rails-testing/SKILL.mdsource content
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 | |
| 2 | Test Data Management | CRITICAL | |
| 3 | Model Testing | HIGH | |
| 4 | Request & Controller Testing | HIGH | |
| 5 | System & Acceptance Testing | MEDIUM-HIGH | |
| 6 | Async & Background Job Testing | MEDIUM | |
| 7 | Test Performance & Reliability | MEDIUM | |
| 8 | Test Organization & Maintenance | LOW-MEDIUM | |
Quick Reference
1. Test Design & Structure (CRITICAL)
- Use four-phase test structure (setup, exercise, verify, teardown)design-four-phase-test
- Test observable behavior, not internal implementationdesign-behavior-over-implementation
- One logical expectation per test for precise failure diagnosisdesign-one-assertion-per-test
- Write test names that read like specificationsdesign-descriptive-test-names
- Make all test data visible within the test itselfdesign-avoid-mystery-guest
- No if/else or loops in test codedesign-avoid-conditional-logic
- Name subjects explicitly instead of using implicit subjectdesign-explicit-subject
2. Test Data Management (CRITICAL)
- Use composable factory traits instead of separate factoriesdata-factory-traits
- Specify only attributes relevant to the testdata-minimal-attributes
- Prefer build/build_stubbed over create when persistence isn't neededdata-build-over-create
- Use factories instead of shared fixturesdata-avoid-fixture-coupling
- Use transient attributes for complex factory setupdata-transient-attributes
- Use sequences for uniqueness-constrained fieldsdata-sequence-unique-values
3. Model Testing (HIGH)
- Test validations with boundary cases, not just happy pathmodel-test-validations
- Test associations explicitly including dependent behaviormodel-test-associations
- Test scopes with matching and non-matching recordsmodel-test-scopes
- Test callback side effects, not callback existencemodel-test-callbacks-sparingly
- Test public methods with input/output pairs across scenariosmodel-test-custom-methods
- Don't test ActiveRecord or framework behaviormodel-avoid-testing-framework
- Test enum transitions and generated scopesmodel-test-enums
4. Request & Controller Testing (HIGH)
- Use request specs over deprecated controller specsrequest-over-controller-specs
- Assert HTTP status codes explicitlyrequest-test-response-status
- Test authentication boundaries for every protected endpointrequest-test-authentication
- Test authorization for each rolerequest-test-authorization
- Test parameter validation and edge casesrequest-test-params-validation
- Assert JSON response structure for API endpointsrequest-json-response-structure
5. System & Acceptance Testing (MEDIUM-HIGH)
- Encapsulate page interactions in page objectssystem-page-objects
- Use accessible selectors over CSS/XPathsystem-use-accessible-selectors
- Never use sleep — rely on Capybara's built-in waitingsystem-avoid-sleep
- Reserve system tests for critical user journeyssystem-test-critical-paths
- Use truncation strategy for system test database cleanupsystem-database-state
- Capture screenshots on system test failuresystem-screenshot-on-failure
6. Async & Background Job Testing (MEDIUM)
- Test enqueue and perform separatelyasync-separate-enqueue-from-perform
- Default to Sidekiq fake mode globallyasync-use-fake-mode-default
- Test job perform method directlyasync-test-job-perform
- Test mailer delivery with enqueued mail matcherasync-test-mailer-delivery
- Account for transaction-aware job enqueuing in Rails 7.2+async-test-after-commit
7. Test Performance & Reliability (MEDIUM)
- Run tests in parallel across CPU coresperf-parallel-tests
- Use transaction strategy for non-system testsperf-database-strategy
- Profile and fix the slowest specsperf-profile-slow-specs
- Quarantine flaky tests instead of retryingperf-quarantine-flaky-tests
- Never mutate state created in before(:all)perf-avoid-before-all-mutation
8. Test Organization & Maintenance (LOW-MEDIUM)
- Limit context nesting to 3 levelsorg-avoid-deep-nesting
- Use shared examples only for true behavioral contractsorg-shared-examples-sparingly
- Extract custom matchers for repeated domain assertionsorg-custom-matchers
- Mirror app directory structure in spec directoryorg-file-structure-mirrors-app
How to Use
Read individual reference files for detailed explanations and code examples:
- Section definitions - Category structure and impact levels
- Rule template - Template for adding new rules
Reference Files
| File | Description |
|---|---|
| references/_sections.md | Category definitions and ordering |
| assets/templates/_template.md | Template for new rules |
| metadata.json | Version and reference information |