testing-patterns

Write and organize Rails specs with RSpec, Capybara, and FactoryBot.

6|1|Updated Feb 4, 2026
One-click install
npx skills add https://github.com/RoleModel/rolemodel-skills --skill testing-patterns-rolemodel
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: testing-patterns
Source: https://github.com/RoleModel/rolemodel-skills/tree/main/skills/testing-patterns
Command: npx skills add https://github.com/RoleModel/rolemodel-skills --skill testing-patterns-rolemodel

SYSTEM DOCUMENTATION & REQUIREMENTS

## What problem does it solve? This Skill helps Rails teams ensure features work correctly by writing automated tests using RSpec, Capybara, and FactoryBot. It prevents regressions and speeds up development.

## Core Features & Use Cases

  • RSpec for unit and model tests
  • Capybara for system/integration tests
  • FactoryBot for test data
  • Use when implementing features, fixing bugs, or when the user mentions testing, specs, RSpec, Capybara, or test data.

### Quick Start Use the testing-patterns skill to run your test suite with bundle exec rspec.

Frequently Asked Questions about testing-patterns

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

FAQPage Schema
How do I organize RSpec tests in Rails to avoid duplication?

Organize RSpec tests using descriptive context blocks and let/let! variables to set up test data cleanly. This pattern prevents duplication and keeps your Rails specs maintainable as the test suite grows.

What's the best way to write reliable Capybara system tests in Rails?

Write reliable Capybara system tests by avoiding manual server startup and using established testing patterns. This ensures your integration tests run consistently without flakiness during automated test workflows.

How do I set up test data in Rails specs without fixtures?

Use FactoryBot to generate test data instead of manual fixtures. It allows you to define dynamic and reusable factories, speeding up development and ensuring your RSpec tests have consistent data contexts.

Do I need to configure RSpec and Capybara before writing Rails system tests?

Yes, you must configure RSpec, Capybara, and FactoryBot in your Rails project before writing tests. Proper setup is required to execute specs correctly and apply reliable testing patterns during feature development.

Why does my Capybara system test fail to find elements on the page?

Capybara system tests often fail due to timing issues or manual server startup conflicts. Using established testing patterns and avoiding manual startup helps synchronize interactions and prevents flaky test failures.

When should I use let versus let! in RSpec?

Use let for lazy evaluation when the variable is only needed in specific tests, and let! to force evaluation before each test runs. Choosing correctly optimizes test speed and prevents unexpected nil values in Rails specs.