rspec-model-testing

Generate RSpec tests for ActiveRecord models covering validations, associations, scopes, and methods.

4|Updated Feb 16, 2017
One-click install
npx skills add https://github.com/nekorush14/dotfiles --skill rspec-model-testing
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: rspec-model-testing
Source: https://github.com/nekorush14/dotfiles/tree/main/configs/claude/skills/rspec-model-testing
Command: npx skills add https://github.com/nekorush14/dotfiles --skill rspec-model-testing

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill provides a blueprint for writing thorough RSpec model specs, covering validations, associations, scopes, callbacks, and class/instance methods.

Core Features & Use Cases

  • Shoulda Matchers & Custom Tests: Validate common patterns plus bespoke validations.
  • Associations & Validations: Ensure data integrity and correct relationships.
  • Scopes & Callbacks: Verify query behavior and lifecycle hooks.

Quick Start

Write a user_spec.rb that checks presence validations, a has_many association, a scope named recent, and a custom instance method like full_name.

Frequently Asked Questions about rspec-model-testing

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

FAQPage Schema
How do I write RSpec tests for Rails model validations?

RSpec model tests verify validations using Shoulda Matchers, which provide concise syntax for presence, uniqueness, and format checks. Write describe blocks for each validation type, then use matchers like `validate_presence_of` to assert that your ActiveRecord model enforces the correct rules before save.

What's the best way to test Rails associations in RSpec?

Test associations by verifying the relationship type and dependent behavior. Use Shoulda Matchers like `have_many`, `belongs_to`, and `has_one` to confirm that your model declares the correct associations, then write separate specs for callback and scope behavior tied to those relationships.

Can I test Rails model scopes and callbacks with RSpec?

Yes. Create specs that call your custom scopes with test data and assert the returned records match expectations. For callbacks, test that lifecycle hooks execute at the right stage—use instance methods or query assertions to verify state changes triggered by create, update, or destroy events.

Do I need Shoulda Matchers to test ActiveRecord models in RSpec?

Shoulda Matchers are optional but recommended. They reduce boilerplate by replacing manual assertions for common patterns like validations and associations. Without them, you can still write custom RSpec specs, but matchers make tests more readable and maintainable.

How do I structure RSpec model tests for edge cases and custom methods?

Organize specs into nested describe blocks by feature: validations, associations, scopes, callbacks, and custom methods. For edge cases, write context blocks that set up specific conditions, then assert behavior under those constraints. Use descriptive test names that document intent.

What should I test in my Rails models before writing implementation code?

Follow TDD by writing model specs first: validate presence and uniqueness rules, confirm association counts and types, verify scope queries return correct subsets, and test custom instance and class methods. This blueprint ensures data integrity and correct behavior from the start.