factory_bot
factory_bot is a Ruby test data library that replaces fixtures with a flexible factory pattern, allowing developers to define and generate test objects easily. It supports multiple build strategies and works seamlessly with Rails applications through the factory_bot_rails gem.
Key facts
Objective fields from the source. Values we can't verify are shown as “Unknown” rather than guessed.
| Field | Value |
|---|---|
| Repository | thoughtbot/factory_bot |
| Owner | thoughtbot |
| Primary language | Ruby |
| License | MIT — OSI-approved |
| Stars | 8.2k |
| Forks | 2.6k |
| Open issues | 71 |
| Latest release | v6.6.0 (2026-05-04) |
| Last updated | 2026-06-22 |
| Source | https://github.com/thoughtbot/factory_bot |
What factory_bot is
A mature Ruby gem providing factories (object templates) with multiple build strategies (save to DB, in-memory, attributes-only, stubbed), trait composition, and inheritance. Integrates with Rails ORM and test frameworks via adapters documented in the wiki.
Get the factory_bot source
Clone the repository and explore it locally.
git clone https://github.com/thoughtbot/factory_bot.gitcd factory_bot# follow the project's README for install & configurationNeed it deployed, integrated, or customized instead? DEV.co ships production installs.
Best use cases
Implementation considerations
- Install via `bundle add factory_bot` or `gem install factory_bot`; for Rails projects, also add factory_bot_rails gem for Rails-specific helpers.
- Check supported Ruby versions in `.github/workflows/build.yml` to ensure compatibility with your Ruby runtime.
- Define factories in `spec/factories` or `test/factories` directory; use traits and inheritance to reduce duplication and keep definitions DRY.
- Choose appropriate build strategy per test (create, build, attributes_for, build_stubbed) to balance realism and speed.
- Monitor factory usage patterns with FactoryTrace tool to identify and remove unused factories as codebase evolves.
When to avoid it — and what to weigh
- Non-Rails Ruby Projects Without Adapter — factory_bot requires explicit setup outside Rails. If using Sequel, DataMapper, or non-ORM code, integration effort increases and community support is limited.
- Performance-Critical Test Suites at Scale — Extensive use of factories with deep associations can slow test runs due to repeated object creation and validation. May need careful profiling and optimization with FactoryTrace.
- Team Unfamiliar with Ruby/Rails Conventions — Requires understanding of Ruby DSL, Rails associations, and test-driven development patterns. Learning curve steeper for teams new to Ruby or the factory pattern.
- Strict No-Network or Offline Testing — If tests must avoid all database I/O and external calls, using `build` or `attributes_for` strategies requires discipline; default `create` strategy persists to DB.
License & commercial use
MIT License (permissive, OSI-approved). Allows use, modification, distribution, and commercial use with attribution and no warranty.
MIT license permits commercial use in proprietary products without royalties or source disclosure. No legal review needed for license compliance, but verify internal IP policies. No official SLA or commercial support tier stated in the data; commercial support may be available via thoughtbot (vendor) but requires separate inquiry.
DEV.co evaluation signals
Editorial assessment — not user reviews. Directional, with an explicit confidence level.
| Signal | Assessment |
|---|---|
| Maintenance | Active |
| Documentation | Strong |
| License clarity | Clear |
| Deployment complexity | Low |
| DEV.co fit | Strong |
| Assessment confidence | High |
No inherent security vulnerabilities disclosed in the data. Security considerations are inherited from the host Ruby/Rails environment and database. Ensure test data does not include production secrets or PII; factory definitions should use fixtures or environment-based values for sensitive data. No security audit or vulnerability history provided in the data; review the GitHub security advisory feed and dependencies for transitive risk.
Alternatives to consider
Fabrication
Lightweight DSL for Ruby object generation with similar factory pattern. Smaller community and fewer integrations; consider if you prefer a simpler, less opinionated tool.
Fixtures (Rails native)
Built-in Rails fixture files (YAML/CSV). No external dependency but less readable, harder to maintain, and inflexible compared to factories for dynamic test data.
Sequel factories or custom builders
For non-Rails projects or Sequel ORM, custom factory patterns or Sequel-native builders may reduce dependency bloat. Requires in-house support and standardization.
Build on factory_bot with DEV.co software developers
Evaluate factory_bot for your Rails or Ruby project. Check the factory_bot book and wiki for detailed guides, then integrate via Gemfile. Start with a single test suite and scale as needed.
Talk to DEV.coRelated open-source tools
Surfaced by semantic similarity across the DEV.co open-source index.
Related on DEV.co
Explore the category and the services that help you build with it.
factory_bot FAQ
Does factory_bot work without Rails?
What is the difference between build, create, and attributes_for?
How do I handle associations in factories?
Is factory_bot suitable for large test suites?
Software development & web development with DEV.co
From first prototype to production, DEV.co delivers software development services around tools like factory_bot. Our software development agency staffs experienced software developers and web developers for custom software development, web development, integrations, and ongoing support across open-source testing and beyond.
Ready to streamline your Ruby test suite?
Evaluate factory_bot for your Rails or Ruby project. Check the factory_bot book and wiki for detailed guides, then integrate via Gemfile. Start with a single test suite and scale as needed.