whatisgithub

What is factory_bot?

foca/factory_bot — explained in plain English

Analysis updated 2026-08-08 · repo last pushed 2022-06-28

Audience · developerComplexity · 2/5DormantSetup · moderate

In one sentence

factory_bot is a Ruby library that lets developers define reusable templates for generating realistic test data, so you don't have to manually create sample records every time you run a test.

Mindmap

mindmap
  root((repo))
    What it does
      Reusable test data templates
      Multiple build strategies
      Factory inheritance
    Use cases
      E-commerce checkout testing
      Order and product tests
      User role testing
    Tech stack
      Ruby
      Rails integration
      Testing frameworks
    Audience
      Ruby developers
      Rails teams
      Test maintainability
    Ecosystem
      Active since 2008
      Maintained by thoughtbot
      FactoryTrace companion
      Rails integration gem

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

What do people build with it?

USE CASE 1

Define factories for customers, products, and orders to test e-commerce checkout flows without repetitive setup code.

USE CASE 2

Create separate factories for regular users and admin users to test role-based access logic.

USE CASE 3

Generate stubbed objects that pretend to exist so you can test code in isolation without touching the database.

USE CASE 4

Use FactoryTrace to find and remove unused factories and traits to keep your test suite clean.

What is it built with?

RubyRails

How does it compare?

foca/factory_bot000madz000/rfid-attendance00kaku/gallery-slider-block
LanguageTypeScriptJavaScript
Last pushed2022-06-282024-07-222021-05-19
MaintenanceDormantDormantDormant
Setup difficultymoderateeasyeasy
Complexity2/52/52/5
Audiencedeveloperdevelopergeneral

Figures from each repo's GitHub metadata at analysis time.

How do you get it running?

Difficulty · moderate Time to first run · 30min

Requires a Ruby application with an existing test framework and optionally Rails for the companion integration gem.

No license information provided in the explanation.

So what is it?

factory_bot is a tool for Ruby developers who need realistic test data when writing automated tests for their applications. Instead of manually creating sample users, orders, or other records every time you run a test, it lets you define reusable templates, called "factories", that generate that data automatically. Think of it as a way to set up convincing placeholder information so you can verify your code works without hand-crafting the same test data over and over. At its core, it works through a straightforward definition syntax where you describe what a typical object looks like. When a test runs, it asks for an instance, and the factory assembles it based on that template. It supports multiple build strategies, you can create fully saved database records, unsaved in-memory instances, plain attribute hashes, or stubbed objects that just pretend to exist. You can also define several factories for the same class, like having one factory for a regular user and another for an admin user, with inheritance to share common traits between them. This is aimed at developers and teams working on Ruby applications, especially those using Rails, who want their test suites to be maintainable and readable. For example, an e-commerce team might define factories for customers, products, and orders, then mix and match them to test checkout flows, discount logic, or inventory updates without writing repetitive setup code in every test file. The project has been around since 2008, originally created by Joe Ferris and maintained by the consultancy thoughtbot. It is a well-established part of the Ruby testing ecosystem. The README is fairly minimal, directing readers to separate documentation for getting started, but it does mention a companion project specifically for Rails integration and a community tool called FactoryTrace that helps identify unused factories and traits to keep your test suite clean.

Copy-paste prompts

Prompt 1
Set up factory_bot in my Ruby test suite and create factories for a User model with name, email, and role attributes, including an admin variant that inherits shared traits.
Prompt 2
Help me choose between factory_bot's build strategies, build, create, attributes_for, and build_stubbed, for testing a Rails order checkout flow where I want to avoid hitting the database.
Prompt 3
Write factory_bot factories for an e-commerce app with Customer, Product, and Order models, using inheritance so that a VIP customer factory shares common traits with a regular customer factory.
Prompt 4
Configure FactoryTrace in my Ruby test suite to detect and report any unused factories and traits so I can clean up my test data definitions.

Frequently asked questions

What is factory_bot?

factory_bot is a Ruby library that lets developers define reusable templates for generating realistic test data, so you don't have to manually create sample records every time you run a test.

Is factory_bot actively maintained?

Dormant — no commits in 2+ years (last push 2022-06-28).

What license does factory_bot use?

No license information provided in the explanation.

How hard is factory_bot to set up?

Setup difficulty is rated moderate, with roughly 30min to a first successful run.

Who is factory_bot for?

Mainly developer.

Open on GitHub → Ask about another repo

This repo across BitVibe Labs

Verify against the repo before relying on details.