Factory Bot

Define factories, sequences, traits, and associations for RSpec test data.

3|Updated Jan 9, 2026
One-click install
npx skills add https://github.com/bastos/ruby-plugin-marketplace --skill factory-bot
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: Factory Bot
Source: https://github.com/bastos/ruby-plugin-marketplace/tree/main/plugins/rspec/skills/factory-bot
Command: npx skills add https://github.com/bastos/ruby-plugin-marketplace --skill factory-bot

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Factory Bot provides a framework for setting up Ruby objects as test data, replacing fixtures with a more flexible and maintainable approach.

Core Features & Use Cases

  • Defining factories: create reusable factories that map to models.
  • Sequences and dynamic attributes: generate unique values and computed fields.
  • Associations and traits: compose complex data graphs with transient attributes and callbacks.

Quick Start

Create a simple factory for a User and demonstrate basic build and create usage in an RSpec example.

Frequently Asked Questions about Factory Bot

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

FAQPage Schema
How do I set up test data in Rails using FactoryBot factories?

FactoryBot replaces fixtures in Rails by defining reusable factories mapped to models. You define factories to create consistent test objects, then call build or create in RSpec examples to generate the required data.

What's the best way to generate unique dynamic attributes in FactoryBot?

Dynamic attributes in FactoryBot are generated using sequences. Sequences provide unique computed values for fields like emails, ensuring consistent object creation without duplicate data conflicts across multiple test runs.

How do FactoryBot traits and associations help compose complex test data?

Traits and associations in FactoryBot allow you to compose complex data graphs. Traits define reusable model variations, while associations link factories together, enabling you to build interconnected objects with transient attributes and lifecycle callbacks.

Can I use FactoryBot to replace fixtures in RSpec workflows?

Yes, FactoryBot integrates directly with RSpec workflows to replace static fixtures. It provides flexible syntax for defining factories, sequences, and traits, allowing you to maintain reusable test data patterns instead of managing rigid fixture files.

When should I use transient attributes and callbacks in FactoryBot factories?

Transient attributes and callbacks in FactoryBot are used when you need to pass temporary data to a factory or trigger lifecycle events. They allow computed fields and conditional logic during object creation to support complex testing workflows.