rspec-testing
This skill should be used when writing, reviewing, or improving RSpec tests for Ruby on Rails applications. Use this skill for all testing tasks including model specs, controller specs, system specs, component specs, service specs, and integration tests. The skill provides comprehensive RSpec best practices from Better Specs and thoughtbot guides.
What this skill does
# RSpec Testing for Rails
## Overview
Write comprehensive, maintainable RSpec tests following industry best practices. This skill combines guidance from Better Specs and thoughtbot's testing guides to produce high-quality test coverage for Rails applications.
## Core Testing Principles
### 1. Test-Driven Development (TDD)
Follow the Red-Green-Refactor cycle:
- **Red**: Write failing tests that define expected behavior
- **Green**: Implement minimal code to make tests pass
- **Refactor**: Improve code while tests continue to pass
### 2. Test Structure (Arrange-Act-Assert)
Organize tests with clear phases separated by newlines:
```ruby
it 'creates a new article' do
# Arrange - set up test data
user = create(:user)
attributes = {title: 'Test Article', body: 'Content here'}
# Act - perform the action
article = Article.create(attributes)
# Assert - verify the outcome
expect(article).to be_persisted
expect(article.title).to eq('Test Article')
end
```
### 3. Single Responsibility
Each test should verify one behavior. For unit tests, use one expectation per test. For integration tests, multiple expectations are acceptable when testing a complete flow.
### 4. Test Real Behavior
Avoid over-mocking. Test actual application behavior when possible. Only stub external services, slow operations, and dependencies outside your control.
## Test Type Decision Tree
### When to Write Model Specs
Use model specs (`spec/models/`) for:
- Validations
- Associations
- Scopes
- Instance methods
- Class methods
- Enums and constants
- Database constraints
**Example:**
```ruby
# spec/models/article_spec.rb
RSpec.describe Article do
describe 'validations' do
it 'validates presence of title' do
article = build(:article, title: nil)
expect(article).not_to be_valid
expect(article.errors[:title]).to include("can't be blank")
end
end
describe 'associations' do
it { is_expected.to belong_to(:user) }
it { is_expected.to have_many(:comments) }
end
describe '#published?' do
it 'returns true when status is published' do
article = build(:article, status: :published)
expect(article.published?).to be true
end
end
end
```
### When to Write Controller Specs
Use controller specs (`spec/controllers/`) for:
- Authorization checks (Pundit/CanCanCan)
- Request routing and parameter handling
- Response status codes
- Instance variable assignments
- Flash messages
- Redirects
**Example:**
```ruby
# spec/controllers/articles_controller_spec.rb
RSpec.describe ArticlesController do
describe 'POST #create' do
context 'with valid parameters' do
it 'creates a new article and redirects' do
user = create(:user)
session[:user_id] = user.id
valid_attributes = {
title: 'Test Article',
body: 'Article content'
}
expect do
post :create, params: {article: valid_attributes}
end.to change(Article, :count).by(1)
expect(response).to redirect_to(Article.last)
end
end
context 'with invalid parameters' do
it 'does not create article and renders new template' do
user = create(:user)
session[:user_id] = user.id
invalid_attributes = {title: '', body: ''}
expect do
post :create, params: {article: invalid_attributes}
end.not_to change(Article, :count)
expect(response).to render_template(:new)
end
end
end
end
```
### When to Write System Specs
Use system specs (`spec/system/`) for:
- End-to-end user workflows
- Multi-step interactions
- JavaScript functionality
- Form submissions
- Navigation flows
- Real user scenarios
**Naming convention:** `user_action_spec.rb` or `feature_description_spec.rb`
**Example:**
```ruby
# spec/system/article_creation_spec.rb
RSpec.describe 'Article Creation' do
it 'allows a user to create a new article' do
user = create(:user)
# Sign in
visit '/login'
fill_in 'Email', with: user.email
fill_in 'Password', with: 'password'
click_button 'Sign In'
# Navigate to new article page
click_link 'New Article'
expect(page).to have_current_path(new_article_path)
# Fill out the article form
fill_in 'Title', with: 'My Test Article'
fill_in 'Body', with: 'This is the article content'
select 'Published', from: 'Status'
# Submit the form
click_button 'Create Article'
expect(page).to have_content('Article created successfully!')
expect(page).to have_content('My Test Article')
end
end
```
### When to Write Component Specs
Use component specs (`spec/components/`) for:
- ViewComponent rendering
- Variant behavior
- Slot functionality
- Conditional rendering
- Component attributes
**Example:**
```ruby
# spec/components/button_component_spec.rb
RSpec.describe ButtonComponent, type: :component do
describe 'variants' do
it 'renders primary variant' do
render_inline(described_class.new(variant: :primary)) { 'Click me' }
button = page.find('button')
expect(button[:class]).to include('btn-primary')
expect(page).to have_button('Click me')
end
it 'renders secondary variant' do
render_inline(described_class.new(variant: :secondary)) { 'Cancel' }
button = page.find('button')
expect(button[:class]).to include('btn-secondary')
end
end
end
```
### When to Write Service/Integration Specs
Use service/integration specs (`spec/services/`, `spec/integration/`) for:
- Complex business logic
- Multi-step workflows
- External API integrations
- Background job processing
- Data transformations
## RSpec Syntax & Style Guide
### Describe Blocks
Use Ruby documentation conventions:
- `.method_name` for class methods
- `#method_name` for instance methods
```ruby
describe '.find_by_title' do # class method
describe '#publish' do # instance method
describe 'validations' do # grouping
```
### Context Blocks
Start with "when," "with," or "without":
```ruby
context 'when user is admin' do
context 'with valid parameters' do
context 'without authentication' do
```
### It Blocks
- Keep descriptions under 40 characters
- Use third-person present tense
- **Never** use "should" in descriptions
```ruby
# ✅ Good
it 'creates a new article' do
it 'validates presence of title' do
it 'redirects to dashboard' do
# ❌ Bad
it 'should create a new article' do
it 'should validate presence of title' do
```
### Expectations
Always use `expect` syntax (never `should`):
```ruby
# ✅ Good
expect(article).to be_valid
expect(response).to have_http_status(:success)
expect { action }.to change(Article, :count).by(1)
# ❌ Bad (deprecated)
article.should be_valid
response.should have_http_status(:success)
```
### One-Liners
Use `is_expected` for concise one-line specs:
```ruby
subject { article }
it { is_expected.to be_valid }
it { is_expected.to be_persisted }
```
## System Test Best Practices
### Authentication in System Tests
Test authentication flows directly without stubbing:
```ruby
# Good - test the actual login flow
visit '/login'
fill_in 'Email', with: user.email
fill_in 'Password', with: 'password'
click_button 'Sign In'
expect(page).to have_content('Dashboard')
```
### Controller Test Authentication
For controller tests, use direct session assignment rather than stubbing:
```ruby
# ✅ Good - direct session assignment
session[:user_id] = user.id
# ❌ Avoid - stubbing authentication
allow_any_instance_of(Controller).to receive(:logged_in?).and_return(true)
```
### Avoid CSS Class Testing
Don't test implementation details like CSS utility classes. Test semantic selectors and content:
```ruby
# ✅ Good - semantic selectors
expect(page).to have_selector(:test_id, 'user-modal')
expect(page).to have_css("[aria-hidden='false']")
expect(page).to have_content('Success message')
expect(page).to have_button('Submit')
# ❌ Bad - coupling to CSS implementation
expect(page).to have_css('.opacity-100'Related in Design
contribute
IncludedLocal-only OSS contribution command center. Auto-refreshes the user's in-flight PR and issue state on invoke so conversations start with full context — no need to brief Claude on what's in flight. Helps the user find issues to contribute to on GitHub, builds per-repo dossiers of what each upstream expects (CLA, DCO, branch convention, AI policy, draft-first, review bots, issue templates), runs deterministic gates before any external action so AI-assisted contributions don't reach maintainers as slop. State is markdown-only: candidate files at ~/.contribute-system/candidates/, repo dossiers at ~/.contribute-system/research/, append-only event log at ~/.contribute-system/log.jsonl. No database, no cloud calls. Use when the user asks about their PRs / issues / contributions, wants to find new work to take on, claim an issue, build/refresh a repo's dossier, or draft a Design Issue or PR. Trigger with "/contribute", "what's my PR status", "find a contribution", "claim issue X", "draft a Design Issue for Y", "refresh dossier for Z".
architectural-analysis
IncludedUser-triggered deep architectural analysis of a codebase or scoped subtree across eight modes — information architecture, data flow, integration points, UI surfaces, interaction patterns, data model, control flow, and failure modes. This skill should be used when the user asks to "diagram this codebase," "map the architecture," "show the data flow," "give me an ERD," "trace control flow," "find the integration points," "verify the layout pattern," "audit the UX architecture," or any similar request whose primary deliverable is mermaid diagrams plus cited reports under docs/architecture/. Dispatches haiku/sonnet sub-agents in parallel for per-mode exploration, then verifies every citation mechanically before any node lands in a diagram. Not for one-off prose explanations of code (use code-explanation) or for high-level system design from scratch (use system-design).
mcp
IncludedModel Context Protocol (MCP) server development and tool management. Languages: Python, TypeScript. Capabilities: build MCP servers, integrate external APIs, discover/execute MCP tools, manage multi-server configs, design agent-centric tools. Actions: create, build, integrate, discover, execute, configure MCP servers/tools. Keywords: MCP, Model Context Protocol, MCP server, MCP tool, stdio transport, SSE transport, tool discovery, resource provider, prompt template, external API integration, Gemini CLI MCP, Claude MCP, agent tools, tool execution, server config. Use when: building MCP servers, integrating external APIs as MCP tools, discovering available MCP tools, executing MCP capabilities, configuring multi-server setups, designing tools for AI agents.
react-native-skia
IncludedDesign, build, debug, and optimise high-polish animated graphics in React Native or Expo using @shopify/react-native-skia, Reanimated, and Gesture Handler. Use when the user wants canvas-driven UI, shaders, paths, rich text, image filters, sprite fields, Skottie, video frames, snapshots, web CanvasKit setup, or performance tuning for custom motion-heavy elements such as loaders, hero art, cards, charts, progress indicators, particle systems, or gesture-driven surfaces. Also use when the user asks for fluid, glow, glass, blob, parallax, 60fps/120fps, or GPU-friendly animated effects in React Native, even if they do not explicitly say "Skia". Do not use for ordinary form/layout work with standard views.
plaid
IncludedProduct Led AI Development — guides founders from idea to launched product. Six capabilities: Idea (discover a product idea), Validate (pressure-test the idea against fatal flaws, problem reality, competition, and 2-week MVP feasibility), Plan (vision intake + document generation), Design (translate image references into a design.md spec), Launch (go-to-market strategy), and Build (roadmap execution). Use when someone says "PLAID", "plaid idea", "help me find an idea", "product idea", "idea from my business", "idea from my expertise", "plaid validate", "validate my idea", "pressure-test", "is this idea good", "find fatal flaws", "validate the problem", "plan a product", "define my vision", "generate a PRD", "product strategy", "plaid design", "design from image", "translate image to design", "create design.md", "extract design tokens", "plaid launch", "go-to-market", "launch plan", "GTM strategy", "launch playbook", "plaid build", "build the app", "start building", or "execute the roadmap".
nextjs-framer-motion-animations
IncludedAdds production-safe Motion for React or Framer Motion animations to Next.js apps, including reveal, hover and tap micro-interactions, whileInView, stagger, AnimatePresence, layout and layoutId transitions, reorder, scroll-linked UI, and lightweight route-content transitions. Use when the user asks to add, refactor, or debug Motion or Framer Motion in App Router or Pages Router codebases, especially around server/client boundaries, reduced motion, LazyMotion, bundle size, hydration, or route transitions. Avoid for GSAP-style timelines, WebGL or 3D scenes, heavy scroll storytelling, or CSS-only effects unless Motion is explicitly requested.