Skip to main content
skill CX Codex

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.

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add Mindrally/skills --skill rspec -a claude-code
Open on GitHub

What 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-code

2Manually: put the files in place

~/.claude/skills/rspec/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/rspec/

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

Similar skills

All skills for Testing and QA →

From the same set214

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor