RSpec Mocks

Create RSpec test doubles and spies to isolate Ruby units and verify interactions.

3|Updated Jan 9, 2026
One-click install
npx skills add https://github.com/bastos/ruby-plugin-marketplace --skill rspec-mocks
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: RSpec Mocks
Source: https://github.com/bastos/ruby-plugin-marketplace/tree/main/plugins/rspec/skills/rspec-mocks
Command: npx skills add https://github.com/bastos/ruby-plugin-marketplace --skill rspec-mocks

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Isolate unit tests from external collaborators by providing guidance and patterns for using test doubles in RSpec, enabling focused validation of behavior with minimal coupling.

Core Features & Use Cases

  • Doubles, Verifying Doubles, Partial Doubles, and Spies: choose the right type to model collaborators and verify interfaces.
  • Stubbing and mocking interactions: replace real dependencies with controllable doubles to drive scenarios and assert calls.
  • Best-practice guidance: reduce brittleness with interface verification and boundaries between units.

Quick Start

Create an instance_double for a dependency in your spec and stub or verify its methods to drive and assert isolated behavior.

Frequently Asked Questions about RSpec Mocks

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
What is the difference between verifying doubles and spies in RSpec?

Verifying doubles in RSpec check that stubbed methods actually exist on the real class, whereas spies record interactions after they occur to assert calls against real objects without breaking execution flow.

How do I stub a method on a dependency using RSpec mocks?

To stub a method using RSpec mocks, create an instance_double for the dependency and define its return values. This isolates the unit under test by replacing real collaborators with controllable test doubles.

When should I use partial doubles instead of standard doubles in Ruby tests?

Use partial doubles in Ruby tests when you need to stub specific methods on a real object while keeping its original behavior intact. Standard doubles are pure stand-ins, whereas partial doubles wrap existing class instances.

Does using instance_double verify interfaces for Ruby modules?

Yes, using an instance_double verifies interfaces for Ruby modules and classes. It ensures stubbed methods match the real method signatures, preventing tightly coupled tests by failing if the collaborator's interface changes.

What are the limitations of mocking interactions with test doubles?

Mocking interactions with test doubles can lead to brittle tests if overused. The primary limitation is that doubles isolate units from real dependencies, meaning integration bugs between the unit and actual collaborators remain undetected.

Why does my RSpec verifying double fail when stubbing a missing method?

RSpec verifying doubles fail when stubbing a missing method because they validate the method's existence against the real class. This mechanism prevents tightly coupled tests by ensuring stubbed interfaces match the actual implementation.