rspec-coder

Guide developers in writing comprehensive RSpec tests for Ruby and Rails applications.

47|11|Updated Nov 26, 2025
One-click install
npx skills add https://github.com/majesticlabs-dev/majestic-marketplace --skill rspec-coder
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: rspec-coder
Source: https://github.com/majesticlabs-dev/majestic-marketplace/tree/main/plugins/majestic-rails/skills/rspec-coder
Command: npx skills add https://github.com/majesticlabs-dev/majestic-marketplace --skill rspec-coder

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Guides crafting robust RSpec tests for Ruby on Rails, covering syntax, describe/context, fixtures, mocks, and shoulda matchers.

Core Features & Use Cases

  • AAA structure, descriptive contexts, and shoulda matchers
  • Spec and traditional styles, fixtures, and mocks
  • Unit, service, and controller testing patterns

Quick Start

Create a simple spec in spec/models and run rspec

Frequently Asked Questions about rspec-coder

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

FAQPage Schema
How do I write RSpec tests with best practices for Rails applications?

RSpec tests follow the AAA structure: arrange test data with fixtures and let bindings, act by calling the code under test, and assert expected behavior using shoulda matchers. Organize specs with describe blocks for classes and context blocks for conditions, use subject for the object being tested, and apply mocking with allow/expect to isolate units. This approach covers models, services, controllers, and jobs while keeping tests fast and maintainable.

What's the difference between fixtures and mocks in RSpec testing?

Fixtures provide real test data persisted to the database or loaded into memory for integration-style tests, while mocks stub method calls and verify interactions without database hits. Use fixtures for model tests requiring database state and mocks for unit tests of service or controller logic. Minimize database usage by preferring mocks and let bindings to keep tests fast.

How do I organize RSpec spec files for Rails projects?

Place spec files in spec/models, spec/services, spec/controllers, and spec/jobs mirroring your app structure. Name specs with _spec.rb suffix. Use describe blocks for the class name, context blocks for specific scenarios, and let or subject to define test data. This layout and convention enables rspec to auto-discover and run all specs, keeping your test suite organized and executable.

Can I use RSpec for testing controllers and services, not just models?

Yes, RSpec applies to unit, service, and controller testing. Controllers specs verify request handling and response format, service specs test business logic in isolation using mocks to avoid database calls, and model specs validate persistence and validations. Use shoulda matchers for Rails-specific assertions across all spec types and apply AAA structure consistently.

What are common RSpec anti-patterns I should avoid?

Avoid unnecessary requires in spec files, explicit type declarations that duplicate Rails inference, and implementation-focused tests that break when internals change. Test behavior, not implementation details. Skip mocking Rails internals and database-heavy controller tests. Keep specs focused, isolated, and descriptive so they document intent and remain fast.

How do shoulda matchers improve RSpec tests?

Shoulda matchers provide Rails-specific assertions like validates_presence_of, belongs_to, and respond_to that replace verbose custom assertions. They make specs more readable, reduce boilerplate, and catch common validation and association errors early. Use shoulda matchers in model specs to verify Rails conventions quickly while keeping tests declarative.