This skill guides writing comprehensive RSpec tests for Ruby and Rails applications. Use when creating spec files, writing test cases, or testing new features. Covers RSpec syntax, describe/context organization, subject/let patterns, fixtures, mocking with allow/expect, and shoulda matchers.
View on GitHubmajesticlabs-dev/majestic-marketplace
majestic-rails
January 24, 2026
Select agents to install to:
npx add-skill https://github.com/majesticlabs-dev/majestic-marketplace/blob/main/plugins/majestic-rails/skills/rspec-coder/SKILL.md -a claude-code --skill rspec-coderInstallation paths:
.claude/skills/rspec-coder/# RSpec Coder
## Core Philosophy
- **AAA Pattern**: Arrange-Act-Assert structure for clarity
- **Behavior over Implementation**: Test what code does, not how
- **Isolation**: Tests should be independent
- **Descriptive Names**: Blocks should clearly explain behavior
- **Coverage**: Test happy paths AND edge cases
- **Fast Tests**: Minimize database operations
- **Fixtures**: Use fixtures for common data setup
- **Shoulda Matchers**: Use for validations and associations
## Critical Conventions
### ❌ Don't Add `require 'rails_helper'`
RSpec imports via `.rspec` config. Adding manually is redundant.
```ruby
# ✅ GOOD - no require needed
RSpec.describe User do
# ...
end
```
### ❌ Don't Add Redundant Spec Type
RSpec infers type from file location automatically.
```ruby
# ✅ GOOD - type inferred from spec/models/ location
RSpec.describe User do
# ...
end
```
### ✅ Use Namespace WITHOUT Leading `::`
```ruby
# ✅ GOOD - no leading double colons
RSpec.describe DynamicsGp::ERPSynchronizer do
# ...
end
```
## Test Organization
### File Structure
```
spec/
├── models/ # Model unit tests
├── services/ # Service object tests
├── controllers/ # Controller tests
├── requests/ # Request specs (API testing)
├── mailers/ # Mailer tests
├── jobs/ # Background job tests
├── fixtures/ # Test data
├── support/ # Helper modules and shared examples
└── rails_helper.rb # Rails-specific configuration
```
### Using `describe` and `context`
| Block | Purpose | Example |
|-------|---------|---------|
| `describe` | Groups by method/class | `describe "#process"` |
| `context` | Groups by condition | `context "when user is admin"` |
```ruby
RSpec.describe OrderProcessor do
describe "#process" do
context "with valid payment" do
# success tests
end
context "with invalid payment" do
# failure tests
end
end
end
```
## Subject and Let
See [resources/patterns.md](resources/patter