rspec-testing

Guide RSpec test structure, naming, matchers, and VCR/WebMock stubbing for Ruby and Rails.

2|Updated May 15, 2015
One-click install
npx skills add https://github.com/stephendolan/dotfiles --skill rspec-testing
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: rspec-testing
Source: https://github.com/stephendolan/dotfiles/tree/main/claude/skills/ruby-rspec
Command: npx skills add https://github.com/stephendolan/dotfiles --skill rspec-testing

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill provides patterns for writing clear, maintainable RSpec tests, helping developers document behavior and avoid brittle tests.

Core Features & Use Cases

  • Observable Behavior: Write tests that verify user-visible outcomes rather than internal implementation details.
  • Test Organization: Favor flat, descriptive tests to improve readability and maintainability.
  • External Service Stubbing: Guidance on using VCR/WebMock to stub external calls and keep tests fast.

Quick Start

Write an RSpec spec that asserts a page shows "Order confirmed" after checkout.

Frequently Asked Questions about rspec-testing

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

FAQPage Schema
How do I write RSpec tests that focus on user-visible behavior instead of implementation details?

Observable behavior testing in RSpec means asserting what users see or experience—like verifying a checkout page displays 'Order confirmed'—rather than testing internal object state. This approach creates tests that survive refactoring and remain maintainable as your code evolves.

What's the best way to stub external API calls in RSpec tests?

Use VCR or WebMock to stub external service calls in RSpec. VCR records real HTTP interactions and replays them; WebMock intercepts requests directly. Both keep tests fast, isolated, and reliable without depending on live external services.

How should I organize and name RSpec tests for clarity and maintenance?

Favor flat, descriptive test structures with explicit per-test setup in RSpec. Use clear test names that document expected behavior, and write custom matchers for complex assertions. This pattern improves readability and makes test intent obvious to future maintainers.

Can I use RSpec patterns with Rails applications?

Yes. RSpec testing patterns for observable behavior, flat test structures, and external service stubbing apply directly to Rails applications. These patterns help you write clear, maintainable specs that verify user-visible outcomes across your Rails stack.

Why should I avoid testing internal implementation in RSpec?

Testing internal implementation creates brittle tests that break when you refactor code without changing behavior. RSpec patterns emphasize verifying observable outcomes instead, so tests remain stable and document what your application actually does for users.