rspec-best-practices

Enforce RSpec best practices for writing and refactoring Rails tests.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Writing and maintaining reliable RSpec tests for Ruby on Rails apps can be error-prone and hard to scale; this guide consolidates best practices to improve readability, determinism, and test coverage.

Core Features & Use Cases

  • Clear guidance on spec types, factory design, flaky tests, shared examples, deterministic assertions, TDD discipline, and selecting first failing spec.
  • Structured patterns for test organization, naming, and data setup to reduce flakiness and maintenance cost.
  • Guidance on when to write model, controller, system, or job specs to maximize value.

Quick Start

Audit your current RSpec tests and implement the recommended best practices across factories, specs, and example structures.

Frequently Asked Questions about rspec-best-practices

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

FAQPage Schema
What are the best practices for writing RSpec tests in Rails?

RSpec best practices for Rails involve enforcing clear spec types, efficient factory design, shared examples, and deterministic assertions to ensure reliable, maintainable tests. This guidance codifies structured patterns for test organization, naming, and data setup to reduce flakiness and maintenance cost.

How do I fix flaky tests in my Rails application?

To fix flaky tests, apply RSpec best practices by restructuring your data setup and ensuring deterministic assertions. This guide provides structured patterns for test organization and factory design to eliminate non-deterministic behavior in your Rails test suite.

When should I write model, controller, request, or system specs in Rails?

You should write model, controller, request, system, or job specs based on guidance that maximizes testing value. This RSpec best practices guide codifies exactly when to use each spec type across your Ruby on Rails project to ensure reliable coverage.

How do I use shared examples correctly in RSpec?

To use shared examples correctly in RSpec, follow structured patterns for test organization and naming. This guide codifies best practices for designing shared examples to improve readability and reduce maintenance costs across your Rails test suite.

Does TDD workflow discipline improve Rails test coverage?

TDD workflow discipline improves Rails test coverage by codifying guidance on selecting the first failing spec and writing deterministic assertions. Applying these RSpec best practices ensures reliable, maintainable tests and strengthens overall test quality.

What is the best way to audit existing RSpec tests?

The best way to audit existing RSpec tests is to review current specs and implement recommended best practices across factories, example structures, and spec types. This process identifies flaky tests and enforces deterministic assertions for better maintainability.