rspec — Claude Code skill: RSpec testing rules for Ruby
Gives the agent a working set of RSpec conventions for Ruby and Rails: spec organization, test data, isolation. Useful when specs drift and duplicate.
npx skills add Mindrally/skills --skill rspec -a claude-codeWhat rspec does
The skill frames the agent as an expert in Ruby, Rails and RSpec. It carries a list of principles: tests cover typical cases and edge cases, invalid input and error conditions included. describe, context and it blocks get descriptive names, assertions use the expect syntax, and the spec directory mirrors the source tree.
For data, the skill recommends let and let! over heavy setup, and FactoryBot factories over fixtures. Each test stays independent, with external services and databases mocked and methods stubbed. There is a counterweight too: over-mocking is called out, so real behavior gets tested where feasible.
Duplication is handled with shared_examples and shared_context, plus helpers and custom matchers for repeated patterns. The skill ships as a single SKILL.md holding the principles and a sample spec for a User model. It installs no gems and no config, so rspec-rails and FactoryBot need to be in the project before you ask the agent to write tests.
What it helps with
- split a messy spec file into describe and context blocks
- cut duplicated setup across tests
- isolate a test from an external API with a mock
- move repeated assertions into shared_examples
- add edge cases to an existing test
Example prompts for the agent
- Write specs for the User model following the rspec skill
- Break this spec file into describe and context blocks, build data with let and FactoryBot
- Pull the repeated assertions from these tests into shared_examples
How to install rspec
1Skills CLI (Vercel)
npx skills add Mindrally/skills --skill rspec -a claude-code2Manually: put the files in place
~/.claude/skills/rspec/SKILL.mdCopy the whole skill folder; for one project use .claude/skills/rspec/
1Skills CLI (Vercel)
npx skills add Mindrally/skills --skill rspec -a codex2Manually: put the files in place
.agents/skills/rspec/SKILL.mdFor all projects use ~/.agents/skills/
1Skills CLI (Vercel)
npx skills add Mindrally/skills --skill rspec -a cursor2Manually: put the files in place
.cursor/skills/rspec/SKILL.mdCursor also reads .agents/skills/ and .claude/skills/
1GitHub CLI
gh skill install Mindrally/skills rspec2Manually: put the files in place
.github/skills/rspec/SKILL.md1Skills CLI (Vercel)
npx skills add Mindrally/skills --skill rspec -a gemini-cli2Platform CLI
gemini skills install https://github.com/Mindrally/skills --path rspecManually: put the files in place
.devin/skills/rspec/SKILL.mdThe legacy .windsurf/skills/ path still works
Skills CLI (Vercel)
npx skills add Mindrally/skills --skill rspec -a opencodeClaude.ai
Zip the folder and upload it in Settings → Capabilities → Skills
Step by step, with commands for each platform: How to install skills in Claude Code: five ways
Questions about rspec
How do I install rspec in Claude?
Run npx skills add Mindrally/skills --skill rspec -a claude-code. The skill file then sits at ~/.claude/skills/rspec/SKILL.md.
What does the rspec skill do?
It hands the agent a set of RSpec conventions: how to name blocks, how to build data with let and FactoryBot, how to keep tests isolated and free of duplication. The agent applies them whenever it writes or edits specs.
Do I need anything in my project before using it?
The skill only carries the rules text. RSpec and FactoryBot have to be present in the project for the advice to land on real code — the skill does not install them.
Source text
SKILL.md · Apache-2.0
---
name: rspec
description: RSpec testing best practices for Ruby and Rails applications, covering test organization, data management, and isolation patterns.
metadata:
maintainer: Mindrally
source: https://github.com/Mindrally/skills
---
# RSpec Testing Best Practices
You are an expert in Ruby, Rails, and RSpec testing.
## Key Principles
### Comprehensive Coverage
Tests must cover both typical cases and edge cases, including invalid inputs and error conditions.
### Readability and Clarity
- Employ descriptive names for `describe`, `context`, and `it` blocks
- Use the `expect` syntax for improved assertion readability
- Keep test code concise without unnecessary complexity
- Include comments explaining complex logic
### Test Organization
- Use `describe` for classes/modules and `context` for different scenarios
- Use the `subject` helper to prevent repetition when defining objects under test
- Mirror your source file structure within the spec directory
### Test Data Management
- Leverage `let` and `let!` for minimal, necessary setup
- Prefer FactoryBot factories over fixtures for generating test data
- Create only the data necessary for each test
### Test Isolation
- Each test must be independent without shared state between tests
- Mock external services (APIs, databases) and stub methods appropriately
- Avoid over-mocking: test real behavior when feasible
### Reduce Duplication
- Share common behaviors across contexts using `shared_examples`
- Extract repetitive patterns into helpers or custom matchers
- Use `shared_context` for common setup across multiple specs
## Example Structure
```ruby
RSpec.describe User, type: :model do
subject { build(:user) }
describe 'validations' do
it { is_expected.to validate_presence_of(:email) }
it { is_expected.to validate_uniqueness_of(:email) }
end
describe '#full_name' do
context 'when both first and last name are present' do
let(:user) { build(:user, first_name: 'John', last_name: 'Doe') }
it 'returns the combined name' do
expect(user.full_name).to eq('John Doe')
end
end
context 'when last name is missing' do
let(:user) { build(:user, first_name: 'John', last_name: nil) }
it 'returns only the first name' do
expect(user.full_name).to eq('John')
end
end
end
end
```
© Mindrally · Apache-2.0 · Mindrally/skills