rspec-rails

Write Ruby on Rails RSpec specs covering unit, request, feature, and job scopes.

14|8|Updated Aug 9, 2011
One-click install
npx skills add https://github.com/kurko/dotfiles --skill rspec-rails
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: rspec-rails
Source: https://github.com/kurko/dotfiles/tree/main/ai/skills/rspec-rails
Command: npx skills add https://github.com/kurko/dotfiles --skill rspec-rails

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires rspec-rails, capybara, factory_bot_rails, webmock.

What problem does it solve?

Writing comprehensive and well-structured RSpec tests for Ruby on Rails applications can be complex and time-consuming. This Skill guides you in generating high-quality unit, request, feature, and job specs, ensuring your application is thoroughly tested and maintainable, reducing debugging time and improving code quality.

Core Features & Use Cases

  • Structured Test Generation: Helps create RSpec tests following best practices for models, jobs, features, and service objects, including proper use of subject, context, and let.
  • Behavior-Driven Testing: Focuses on testing behavior rather than implementation details, leading to more resilient tests.
  • Use Case: When you're developing a new Rails feature, simply describe the functionality, and the AI will help you scaffold and write the necessary RSpec tests, ensuring full coverage and adherence to testing standards.

Quick Start

Write RSpec tests for the User model, including validations for email and password, and a scope for active users.

Frequently Asked Questions about rspec-rails

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

FAQPage Schema
How do I write comprehensive RSpec tests for Rails models, controllers, and features?

RSpec tests for Rails organize into unit, request, feature, and job specs with clear file structure under spec/. Use subject, context, let/let!, and before hooks to write behavior-focused tests that minimize implementation details and improve maintainability across models, services, and jobs.

What's the best way to structure RSpec test files in a Rails project?

Map spec/ directory structure to your app architecture, placing model specs in spec/models, request specs in spec/requests, feature specs in spec/features, and job specs in spec/jobs. This alignment ensures consistent organization and makes tests easy to locate and maintain.

How do I use factories and test isolation in RSpec Rails specs?

Use factory_bot_rails to create test data and isolate tests by defining clear boundaries within context blocks and let variables. This prevents test interdependencies, ensures each spec runs independently, and makes failures easier to diagnose.

Should I write controller tests or use request and feature specs instead?

Prefer request and feature specs over isolated controller tests when they cover the same behavior. Request specs test HTTP endpoints end-to-end, feature specs simulate user interactions, and both provide better coverage of actual application flow than controller-only tests.

Can I use RSpec with Capybara and WebMock for full Rails test coverage?

Yes. Capybara powers feature specs for browser-like interactions, WebMock stubs external HTTP requests in request and unit specs, and RSpec coordinates all three. This combination enables comprehensive testing from units to full user workflows.

What patterns should I follow when testing Rails services and lib classes?

Test services and lib classes as unit specs with clear examples and behavior-driven assertions. Use subject and let to define the object under test, context blocks to organize scenarios, and focus on verifiable outputs rather than internal state or private method calls.