rspec-service-testing

Write RSpec tests for service objects using instance_double isolation.

22|6|Updated Mar 11, 2026
One-click install
npx skills add https://github.com/igmarin/rails-agent-skills --skill rspec-service-testing-igmarin
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: rspec-service-testing
Source: https://github.com/igmarin/rails-agent-skills/tree/main/rspec-service-testing
Command: npx skills add https://github.com/igmarin/rails-agent-skills --skill rspec-service-testing-igmarin

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Write robust RSpec tests for service objects, API clients, orchestrators, and business logic by emphasizing the public contract and proper isolation.

Core Features & Use Cases

  • Covers instance_double, FactoryBot hash factories, shared_examples, subject/let blocks, context/describe structure, aggregate_failures, travel_to, and error scenario testing.

Quick Start

Create a minimal spec under spec/services for a sample service, focusing on its public interface and the .call method.

Frequently Asked Questions about rspec-service-testing

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

FAQPage Schema
How do I test Rails service objects with RSpec?

Testing Rails service objects with RSpec involves placing specs under spec/services and focusing on the public contract like .call, .find, and .search methods. You use instance_double for strict isolation to ensure robust unit tests.

What is the best way to isolate dependencies in RSpec service tests?

The best way to isolate dependencies in RSpec service tests is using instance_double. This enforces test-first gates and ensures your service object specs remain reliable and maintainable by strictly verifying mocked interactions without hitting real implementations.

How do I structure RSpec tests for business logic and orchestrators?

Structure RSpec tests for business logic and orchestrators using context and describe blocks. Implement shared_examples for reusable patterns, apply aggregate_failures for grouped assertions, and test clear error scenarios to cover the complete public contract.

Can I use FactoryBot hash factories when testing Rails services?

Yes, you can use FactoryBot hash factories when testing Rails services. This approach promotes cleaner data setup within your let blocks and integrates seamlessly with travel_to for time manipulation and testing API clients.

Why does my RSpec service test fail when checking error scenarios?

RSpec service tests for error scenarios fail when they do not define clear error expectations or lack aggregate_failures. You must explicitly test failure paths within your .call method to ensure the service handles invalid states correctly.