RSpec Testing

Generate and debug RSpec unit and integration tests for Ruby and Rails.

11|Updated Jun 19, 2013
One-click install
npx skills add https://github.com/MadBomber/experiments --skill rspec-testing-madbomber
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: RSpec Testing
Source: https://github.com/MadBomber/experiments/tree/main/ai_misc/skills/hoblin-rspec
Command: npx skills add https://github.com/MadBomber/experiments --skill rspec-testing-madbomber

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes scripts (resource) and references (resource) components.

What problem does it solve?

This Skill streamlines the process of writing, understanding, and debugging Ruby and Rails tests using RSpec, ensuring robust and maintainable code.

Core Features & Use Cases

  • Write Specs: Generate new RSpec tests for models, controllers, requests, and more.
  • Fix Failing Tests: Diagnose and resolve common RSpec errors and test failures.
  • Understand Matchers & Doubles: Learn to use RSpec's powerful assertion library and test doubles effectively.
  • Use Case: You're building a new feature and need to write comprehensive unit and integration tests. This Skill provides the patterns and syntax to do so efficiently using RSpec and FactoryBot.

Quick Start

Use the RSpec Testing skill to write a new spec for the User model's full_name method.

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 for a Rails model method?

RSpec testing for Rails models involves defining spec files using RSpec's DSL and matchers to assert expected behavior. This guidance provides patterns for structuring unit tests, generating FactoryBot data, and validating model methods efficiently.

What is the best way to use test doubles in RSpec?

Test doubles in RSpec are objects standing in for real objects to isolate unit tests. You use them to stub methods and mock interactions, ensuring tests run faster without hitting actual database records or external API integrations.

Can I use FactoryBot with RSpec for Rails integration testing?

FactoryBot works seamlessly with RSpec for Rails integration testing. It allows you to define factories generating valid test data, replacing fixtures to provide flexible and maintainable data generation for your test suite.

Why does my RSpec test fail when checking controller responses?

RSpec tests fail when checking controller responses due to incorrect matchers, routing errors, or missing test data. This guidance helps diagnose common RSpec errors by providing patterns for request specs and troubleshooting failing assertions.

Does TDD workflow require understanding RSpec's DSL before writing code?

TDD workflows using RSpec require understanding its DSL to define expected behavior before writing implementation code. This guidance facilitates TDD and BDD workflows by explaining syntax, matchers, and structure needed to write effective tests first.