Use when writing or debugging tests in a Rails application, setting up test infrastructure, or choosing between RSpec and Minitest patterns. Also applies when creating factories, fixtures, shared examples, or mocking external services. Covers test strategy, framework detection, directory structure, and common patterns for all test types.
Generates and debugs Rails tests using RSpec or Minitest patterns, including factories, fixtures, and framework conventions.
npx claudepluginhub chaserx/cpcThis skill inherits all available tools. When active, it can use any tool Claude has access to.
references/minitest-patterns.mdreferences/mocking-services.mdreferences/rspec-patterns.mdGuidance for testing Rails applications using RSpec or Minitest, covering test strategy, framework conventions, and common patterns.
Follow this process when writing or modifying tests:
spec/ (RSpec) or test/ (Minitest)Check project structure to determine the testing framework:
spec/ directory with _spec.rb files → RSpec (with FactoryBot for test data)test/ directory with _test.rb files → Minitest (with YAML fixtures for test data)spec/
├── models/ # Model specs
├── requests/ # Request/controller specs
├── system/ # System specs (browser testing)
├── jobs/ # Background job specs
├── mailers/ # Mailer specs
├── support/ # Shared helpers, custom matchers
├── factories/ # FactoryBot factories
├── rails_helper.rb # Rails-specific config
└── spec_helper.rb # RSpec config
test/
├── models/ # Model tests
├── controllers/ # Controller tests (integration)
├── system/ # System tests
├── jobs/ # Job tests
├── mailers/ # Mailer tests
├── fixtures/ # YAML fixtures
├── test_helper.rb # Test configuration
└── application_system_test_case.rb
it 'updates the user' do
# Arrange
user = create(:user, name: 'Old Name')
# Act
user.update(name: 'New Name')
# Assert
expect(user.reload.name).to eq('New Name')
end
# Focused tests — each verifies one behavior
it 'returns created status' do
post users_path, params: valid_params
expect(response).to have_http_status(:created)
end
it 'creates a user' do
expect { post users_path, params: valid_params }.to change(User, :count).by(1)
end
# Good: tests observable behavior
it 'sends welcome email after registration' do
expect { user.register! }.to have_enqueued_mail(UserMailer, :welcome)
end
# Bad: tests internal method calls
it 'calls the mailer' do
expect(UserMailer).to receive(:welcome).with(user)
user.register!
end
build Over create When PossiblePrefer build(:user) (in-memory) over create(:user) (persisted) when database state is not needed. This speeds up tests significantly.
Each test should set up its own data and not depend on ordering or shared mutable state. Use let (RSpec) or setup (Minitest) for per-test setup.
| Test Type | RSpec Location | Minitest Location |
|---|---|---|
| Model | spec/models/ | test/models/ |
| Controller/Request | spec/requests/ | test/controllers/ |
| System | spec/system/ | test/system/ |
| Job | spec/jobs/ | test/jobs/ |
| Mailer | spec/mailers/ | test/mailers/ |
| Need | RSpec | Minitest |
|---|---|---|
| Create test data | create(:user) | users(:john) |
| Assert equal | expect(x).to eq(y) | assert_equal y, x |
| Assert true | expect(x).to be true | assert x |
| Assert raises | expect { }.to raise_error | assert_raises { } |
| Assert changes | expect { }.to change { } | assert_difference |
# RSpec
bundle exec rspec # all specs
bundle exec rspec spec/models/ # model specs only
bundle exec rspec spec/models/user_spec.rb:42 # single example
rails test # all tests
rails test test/models/ # model tests only
rails test test/models/user_test.rb:15 # single test
For detailed code examples and patterns, consult:
references/rspec-patterns.md — Model specs, request specs, system specs, FactoryBot definitions, shared examples and contextsreferences/minitest-patterns.md — Model tests, controller tests, system tests, fixtures, custom assertions, parallel testingreferences/mocking-services.md — WebMock stubbing, VCR cassette recording, choosing between the twoActivates when the user asks about AI prompts, needs prompt templates, wants to search for prompts, or mentions prompts.chat. Use for discovering, retrieving, and improving prompts.
Search, retrieve, and install Agent Skills from the prompts.chat registry using MCP tools. Use when the user asks to find skills, browse skill catalogs, install a skill for Claude, or extend Claude's capabilities with reusable AI agent components.
Creating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code, generative art, algorithmic art, flow fields, or particle systems. Create original algorithmic art rather than copying existing artists' work to avoid copyright violations.