---
name: "rspec-rails-behavior-driven-tests"
description: "Write clean, readable BDD test specifications for Rails models, requests, and services."
metadata:
  author: "RSpec"
  version: "1.0.0"
  runtime_compatibility:
    - "codex"
    - "claude-code"
    - "cursor"
    - "windsurf"
triggers:
  - "write rspec request spec"
  - "create factory with factorybot"
  - "mock service rspec"
permissions:
  fs_read: true
  fs_write: "workspace"
  shell_exec: false
  net_access: false
---

# RSpec Rails Behavior-Driven Testing & FactoryBot

Configures RSpec Rails: writing describe and context blocks, expectations (expect(...).to eq(...)), creating test mock data with FactoryBot, mocking with RSpec Mocks (allow, expect), and request specs for API endpoints.

## When to Invoke
Invoke this skill whenever you need to:
- write rspec request spec
- create factory with factorybot
- mock service rspec

## Execution SOP & Rules
1. Install rspec-rails and factory_bot_rails; run rails generate rspec:install.
2. Structure spec: describe 'POST /api/orders' do context 'with valid params' do it 'creates an order' ... end.
3. Use FactoryBot: let(:user) { create(:user, :admin) } for clean test data provisioning.
4. Execute tests: bundle exec rspec and review concise documentation output format: rspec -fd.

## Verification Checklist
- Run local linting, syntax validation, and type-checks before reporting completion.
- Ensure all created or modified files adhere to workspace boundaries and avoid uncommitted secrets.
- Verify tests or build commands exit cleanly with return code 0.
