From rails-specialist
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.
npx claudepluginhub chaserx/cpc --plugin rails-specialistThis skill uses the workspace's default tool permissions.
Guidance for testing Rails applications using RSpec or Minitest, covering test strategy, framework conventions, and common patterns.
Generates design tokens/docs from CSS/Tailwind/styled-components codebases, audits visual consistency across 10 dimensions, detects AI slop in UI.
Records polished WebM UI demo videos of web apps using Playwright with cursor overlay, natural pacing, and three-phase scripting. Activates for demo, walkthrough, screen recording, or tutorial requests.
Delivers idiomatic Kotlin patterns for null safety, immutability, sealed classes, coroutines, Flows, extensions, DSL builders, and Gradle DSL. Use when writing, reviewing, refactoring, or designing Kotlin code.
Guidance 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 two