Skip to main content
skill CX Codex

rspec-skill — Claude Code skill: RSpec tests for Ruby

Generates RSpec tests in Ruby with describe/context/it blocks, matchers, let/before hooks, and mocking. Works with Claude Code, Codex, Cursor, GitHub Copilot, and other editors.

MIT 222 installs ★ 393 updated 2026-10-13

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

What rspec-skill does

This skill automates unit test writing in Ruby. When you ask the agent to create a test for a class or method, it produces a full spec with describe blocks for logical sections, context for conditions, and it for individual assertions. It includes ready-made patterns: matchers (eq, include, match_array), stubs with allow/receive, mocks to verify calls, let variables for lazy initialization, and before/after hooks for setup.

Supports core RSpec constructs: equality checks, type assertions, exception handling, state changes (change matcher), and shared_examples for reusable test patterns. Works with instance_double for type-safe mocks and avoids anti-patterns like instance variables instead of let or legacy should syntax.

Requires Ruby with RSpec installed (gem install rspec). The skill watches for triggers — "RSpec", "describe do", "expect().to eq()", "Ruby test", "spec file" — and activates when you mention them in a prompt.

What it helps with

  • write unit tests for a Ruby class with multiple methods
  • build describe blocks with contexts for different scenarios
  • replace instance variables with let blocks and before hooks
  • add mocks and stubs for external dependencies
  • verify that a method calls an external service exactly once

Example prompts for the agent

  • Write RSpec tests for a Calculator class with add and divide methods
  • Create a spec file with describe, context, and it blocks for UserService
  • Refactor tests: replace instance variables with let, add allow/receive for mocking

How to install rspec-skill

1Skills CLI (Vercel)

npx skills add LambdaTest/agent-skills --skill rspec-skill -a claude-code

2Manually: put the files in place

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

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

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about rspec-skill

How do I install rspec-skill in Claude Code?

Run npx skills add LambdaTest/agent-skills --skill rspec-skill -a claude-code, then verify by opening ~/.claude/skills/rspec-skill/SKILL.md.

What does rspec-skill do?

Generates complete RSpec tests with describe/context/it blocks, matchers, let variables, stubs, and mocks. Helps the agent write clean, well-structured unit tests in Ruby.

Which matchers and syntax does the skill support?

Supports expect().to syntax, matchers for equality (eq, eql, equal), comparisons, types, collections, strings, exceptions, and state changes. Ready for instance_double, allow/receive, and shared_examples.

Source text

SKILL.md · MIT
---
name: rspec-skill
description: >
  Generates RSpec tests in Ruby with describe/context/it blocks, matchers,
  let/before hooks, and mocking. Use when user mentions "RSpec", "describe do",
  "expect().to", "Ruby test". Triggers on: "RSpec", "expect().to eq()",
  "describe do", "Ruby test", "spec file".
languages:
  - Ruby
category: unit-testing
license: MIT
metadata:
  author: TestMu AI
  version: "1.0"
---

# RSpec Testing Skill

## Core Patterns

### Basic Test

```ruby
RSpec.describe Calculator do
  subject(:calculator) { described_class.new }

  describe '#add' do
    it 'adds two positive numbers' do
      expect(calculator.add(2, 3)).to eq(5)
    end

    it 'handles negative numbers' do
      expect(calculator.add(-1, 1)).to eq(0)
    end
  end

  describe '#divide' do
    it 'divides evenly' do
      expect(calculator.divide(10, 2)).to eq(5)
    end

    it 'raises on zero divisor' do
      expect { calculator.divide(10, 0) }.to raise_error(ZeroDivisionError)
    end
  end
end
```

### Matchers

```ruby
# Equality
expect(actual).to eq(expected)           # ==
expect(actual).to eql(expected)          # eql?
expect(actual).to equal(expected)        # equal? (same object)
expect(actual).to be(expected)           # equal?

# Comparison
expect(value).to be > 5
expect(value).to be_between(1, 10).inclusive

# Truthiness
expect(value).to be_truthy
expect(value).to be_falsey
expect(value).to be_nil

# Collections
expect(array).to include(3)
expect(array).to contain_exactly(1, 2, 3)
expect(array).to match_array([3, 1, 2])
expect(hash).to include(name: 'Alice')

# Strings
expect(str).to include('hello')
expect(str).to start_with('He')
expect(str).to match(/\d+/)

# Types
expect(obj).to be_a(String)
expect(obj).to be_an_instance_of(MyClass)

# Exceptions
expect { method }.to raise_error(StandardError)
expect { method }.to raise_error(StandardError, /message/)

# Change
expect { user.activate }.to change(user, :active).from(false).to(true)
expect { list.push(1) }.to change(list, :size).by(1)
```

### Hooks and Let

```ruby
RSpec.describe UserService do
  let(:repo) { instance_double(UserRepository) }
  let(:service) { described_class.new(repo) }

  before(:each) do
    allow(repo).to receive(:save).and_return(true)
  end

  after(:each) { cleanup }
  before(:all) { setup_database }
  after(:all) { teardown_database }

  context 'when creating a user' do
    it 'saves to repository' do
      service.create('Alice', '[email protected]')
      expect(repo).to have_received(:save).once
    end
  end
end
```

### Mocking and Stubbing

```ruby
# Doubles
user = double('User', name: 'Alice', email: '[email protected]')
user = instance_double(User, name: 'Alice')

# Stubs
allow(service).to receive(:fetch).and_return(data)
allow(service).to receive(:fetch).with('id').and_return(user)

# Expectations
expect(service).to receive(:save).once
expect(service).to receive(:notify).with('[email protected]')
expect(service).not_to receive(:delete)
```

### Shared Examples

```ruby
RSpec.shared_examples 'a valid model' do
  it { is_expected.to be_valid }
  it { is_expected.to respond_to(:save) }
end

RSpec.describe User do
  subject { described_class.new(name: 'Alice') }
  it_behaves_like 'a valid model'
end
```

### Anti-Patterns

| Bad | Good | Why |
|-----|------|-----|
| `before` with heavy setup | `let` (lazy) | Only evaluates when used |
| No contexts | `context 'when...'` | Clear scenarios |
| Instance variables | `let` blocks | Cleaner, lazier |
| `should` syntax | `expect().to` | Modern RSpec |

## Setup: `gem install rspec` then `rspec --init`
## Run: `bundle exec rspec` or `rspec spec/models/user_spec.rb`
## Config: `.rspec` file with `--format documentation --color`

## Deep Patterns

For advanced patterns, debugging guides, CI/CD integration, and best practices,
see `reference/playbook.md`.

© TestMu AI · MIT · LambdaTest/agent-skills

Similar skills

All skills for Testing and QA →

From the same set47

The whole set →
selenide-skill Generates Java UI tests with Selenide, configuring element selectors, fluent conditions, and automatic waits. CX Codex +1 225installs xunit-skill Gives the coding agent a working pattern for xUnit.net in C#: which attribute to use, how to share fixtures, what to assert. Useful when tests need to match xUnit conventions. CX Codex +1 224installs specflow-skill Drafts SpecFlow BDD suites for C#/.NET: Gherkin feature files plus the step bindings behind them. Useful when a project already runs on NUnit or xUnit. CX Codex +1 223installs serenity-bdd-skill serenity-bdd-skill is a Claude Code skill that creates Java BDD tests with Serenity and the Screenplay pattern. It activates for requests about Serenity, @Steps, or Serenity reports. CX Codex +1 223installs gauge-skill Generates Gauge Markdown test specifications and step implementations in Java, Python, JavaScript, or Ruby. CX Codex +1 218installs behat-skill Generates Behat BDD tests for PHP with Gherkin scenarios and MinkContext for browser checks. Creates feature files, custom contexts and behat.yml config. CX Codex +1 216installs testunit-skill testunit-skill generates Test::Unit tests for Ruby projects: xUnit-style classes, assert methods and fixtures. Fits codebases already running on test-unit rather than RSpec. CX Codex +1 213installs testcafe-skill Generate TestCafe end-to-end tests in JavaScript or TypeScript, from login flows to selector checks. The skill covers local runs and TestMu AI Cloud. CX Codex +1 212installs

Project sponsors

Companies that keep this analytics open