thoughtbot/factory_bot
69.8
Adequate · 26 September 2026
2.6k
lines of production code
Ruby
primary language
4
measurements over time
What this system is
This system is the FactoryBot library, a Ruby tool for defining and managing test data factories. It provides capabilities for creating object instances, managing sequences, and handling associations through various build strategies. The codebase focuses on maintaining compatibility across multiple Rails and Ruby versions while ensuring robust internal refactoring and comprehensive test coverage.
How it got here
2008–2009 — FactoryBot rebranding and test modernization
7 changes.
The library was renamed from FactoryGirl to FactoryBot, introducing a new public API and removing legacy class definitions. The project simultaneously modernized its development infrastructure by migrating the test suite from Test::Unit to RSpec and establishing a Cucumber integration environment with SQLite.
2010–2017 — v6.6.0 refactoring and test expansion
15 changes.
This period focused on the v6.6.0 release, which involved a major internal refactoring of the core library to support modern Ruby and Rails versions while introducing new sequence and callback features. Extensive test coverage was added across acceptance, feature, and unit levels to validate the new class hierarchy, strategy behaviors, and improved error handling.
2018–2026 — development tooling and Rails compatibility
5 changes.
This period focused on enhancing the developer experience by introducing setup scripts, a console utility, and automated changelog generation. Concurrently, the project expanded its test matrix to ensure compatibility with Rails versions 7.0 through 8.0 and improved test infrastructure with thread-safe logging and decorator coverage.
Features
Added developer console and setup scripts
New executable scripts have been added to the bin directory to improve local development workflows. The bin/console script provides an interactive Ruby IRB environment pre-loaded with Bundler and FactoryBot, facilitating easier debugging and testing. The bin/setup script automates the initial environment configuration by running bundle install with strict error handling.
bin · high confidence
Added step definitions for FactoryBot and database assertions
New step definitions have been added to support Cucumber integration with FactoryBot and database verification. The \factory\_bot\_steps.rb\ file introduces steps to dynamically add factory definition files to FactoryBot's search path (both relative and absolute), create factory instances, reload factories, and trigger definition loading. The \database\_steps.rb\ file adds a step to verify that the last created Category record matches expected attributes provided in a Cucumber table, along with a hook to clear all Category records before each scenario.
_features/step\definitions · high confidence
Initialize Cucumber support environment with SQLite and factory definitions
The Cucumber test suite now includes a dedicated support directory containing an environment setup file and factory definitions. The environment file configures the test runtime by requiring ActiveRecord, FactoryBot, and Aruba, while the factory file establishes an in-memory SQLite database and defines a basic Category schema to support feature specifications.
features/support · high confidence
New Rake task to automate changelog generation
A new Rake task, \release:update\_changelog\, has been added to automate the update of the \NEWS.md\ file. When invoked with a version argument, it identifies the last release tag, fetches merged pull requests via the GitHub CLI, and appends a formatted section for the new version to the changelog, preserving any existing unreleased entries.
tasks · high confidence
Removals
Removed legacy Factory class definition
The legacy \Factory\ class definition in \lib/factory\_girl/factory.rb\ has been removed. This cleanup eliminates the empty class stub, reflecting the library's evolution where factory definitions are now handled by the \FactoryGirl\ module and its associated classes rather than a standalone \Factory\ class.
_lib/factory\girl · high confidence
Behavioural changes
Add support for Rails 7.0, 7.1, 7.2, 8.0, and main branch
The gemfile matrix has been expanded to include new Appraisal configurations for Rails 7.0, 7.1, 7.2, 8.0, and the Rails main development branch. This allows the library to be tested against these specific versions of ActiveRecord, ensuring compatibility with the latest and upcoming releases of the Rails framework.
gemfiles · high confidence
FactoryBot v6.6.0: Major internal refactoring and new sequence capabilities
This release introduces a significant internal refactoring of the core library, replacing the previous \AttributeHash\ and \DefinitionProxy\ logic with a new, explicit class hierarchy (\Attribute\, \Declaration\, \Evaluator\, \AttributeAssigner\) to improve maintainability and performance. For users, this brings new sequence features, including the ability to rewind sequences and set their initial values lazily. The library also adds \before(:all)\ and \after(:all)\ callback support, introduces \traits\_for\_enum\ for generating traits from enum values, and allows factories to define aliases for easier referencing. Additionally, linting transactions are now isolated from the ActiveRecord lifecycle, and several deprecated internal methods have been removed.
_lib/factory\bot · high confidence
FactoryGirl renamed to FactoryBot with new public API
The library has been renamed from FactoryGirl to FactoryBot. The old \lib/factory\_girl.rb\ entry point is removed, and a new \lib/factory\_bot.rb\ provides the main interface. This entry point exposes new configuration options (\use\_parent\_strategy\, \automatically\_define\_enum\_traits\, \sequence\_setting\_timeout\) and public methods for linting (\FactoryBot.lint\), managing sequences (\rewind\_sequence\, \set\_sequence\), and accessing factories/strategies via the \Internal\ module. The change also introduces a deprecation warning for version 7.0.
lib · high confidence
Improved error messages and self-referencing trait validation
Factory Bot now provides more helpful feedback when configuration errors occur. If an association receives an invalid factory argument or attribute override, it raises an error suggesting the correct syntax (e.g., 'Did you mean? factory: :name'). Additionally, defining a trait that references itself now raises a clear TraitDefinitionError instead of failing silently or with a confusing stack trace.
_lib/factory\bot/declaration · high confidence
New sequence generation methods and internalized syntax registration
FactoryBot now exposes \generate\ and \generate\_list\ methods in the \FactoryBot::Syntax::Methods\ module, allowing users to retrieve the next value or a list of values from a global or factory-scoped sequence by URI. The syntax DSL (\lib/factory\_bot/syntax/default.rb\) has been restructured to delegate factory, sequence, and trait registration to the new \FactoryBot::Internal\ module, centralizing internal state management while maintaining the existing \define\ and \modify\ entry points.
_lib/factory\bot/syntax · high confidence
Refactor decorator internals to support Ruby 2.7+ and improve reliability
The decorator subsystem has been refactored to address Ruby 2.7 keyword argument warnings and prevent recursive calls in attribute handling. New or updated decorator classes now include \AttributeHash\ to safely aggregate attributes without recursion, \DisallowsDuplicatesRegistry\ to explicitly raise errors on duplicate registrations, \InvocationTracker\ to monitor method calls using modern splat syntax, and \NewConstructor\ to delegate instance creation. These changes ensure compatibility with newer Ruby versions and make factory behavior more predictable by preventing silent failures or warnings during object construction.
_lib/factory\bot/decorator · high confidence
Refactored strategy implementations and enhanced build\_stubbed behavior
The strategy classes in lib/factory\_bot/strategy have been restructured into distinct files (AttributesFor, Build, Create, Null, and Stub). For the build\_stubbed strategy, the change ensures that stubbed models now correctly set created\_at and updated\_at timestamps if they are missing, and it adds support for UUID primary keys and models without ID setters. Additionally, the stub strategy now aligns the \#destroyed state with \#new\_record/\#persisted and allows defining a starting ID for stubs.
_lib/factory\bot/strategy · high confidence
Test coverage
Added acceptance tests for factory definitions and behaviors; Added comprehensive test coverage for FactoryBot core components; Added custom RSpec matchers for testing; Added feature tests for factory definition discovery and reloading; Added shared examples for strategy behavior testing; Added test coverage for FactoryBot strategies; Added test support for thread-safe logging; Added test support macros for in-memory database and deprecation handling; Added tests for AttributeHash decorator; Added tests for association, dynamic, and sequence attribute handling; Added tests for declaration equality and attribute resolution; Migrate test suite to RSpec and update spec configuration; Removed legacy Test::Unit test infrastructure.
Dependencies
factory\_bot 6.6.0 release with Ruby 3.0+ and Rails 8 support
The factory\_bot gem has been updated to version 6.6.0, raising the minimum required Ruby version to 3.0.0 and updating the runtime dependency on activesupport to require version 6.1.0 or higher. This aligns the library with modern Ruby and Rails versions, including support for Rails 8 (activesupport 8.0.3), while also updating development dependencies such as RSpec 3.13, Standard 1.51.1, and Cucumber 10.1.1 to their latest stable releases.
(dependencies) · high confidence
Housekeeping
Repository initialization with development tooling and documentation
The repository has been initialized with essential configuration files for development and testing, including \.gitignore\, \.irbrc\ (providing a \reload!\ helper for the IRB console), \.rspec\, \.simplecov\, \.standard.yml\, \.tool-versions\, and \Appraisals\ for testing against multiple Rails versions. It also includes core documentation files such as \README.md\, \CONTRIBUTING.md\, \CODE\_OF\_CONDUCT.md\, \SECURITY.md\, \NAME.md\, and \GETTING\_STARTED.md\, along with a \Rakefile\ for running specs and linting.
(repo-wide) · high confidence
Written by watchdog.canine.dev from the codebase's own history, inside the signed delivery this page is composed from.
How this codebase got here
This is the PUBLIC form of this artifact. Findings are listed in full, but the details of SECURITY findings — which rule fired, in which file, on which line, and how to fix it — are deliberately withheld, and any secret-scanner results are excluded entirely. Where detail is absent here it was REMOVED FOR PUBLICATION; it is not missing from the analysis. The complete artifact is available from the repository owner.
Score
- CAI 50 → 70 (+19.6)
- Rubric changed (rubric-2026.08.15 → rubric-2026.09.15) — scores are not directly comparable.
Lenses
- Code Health 100 → 100 (+0.0)
- Architecture 94 → 98 (+4.1)
- Maturity 59 → 57 (-1.7)
- Readiness 35 → 74 (+39.0)
- Security 52 → 74 (+21.9)
- Domain Modelling 100 (new)
Resolved (18)
- Coverage not measured — test suite did not build
- Dimension evaluation failed
- High: security finding (details withheld)
- High: security finding (details withheld)
- High: security finding (details withheld)
- High: security finding (details withheld)
- High: security finding (details withheld)
- High: security finding (details withheld)
- High: security finding (details withheld)
- High: security finding (details withheld)
- High: security finding (details withheld)
- High: security finding (details withheld)
- High: security finding (details withheld)
- High: security finding (details withheld)
- LLM evaluation failed
- No exposed public API
- No tests found
- Test reliability not included
New (34)
- CI installs an unverified third-party binary (.github/workflows/docs.yml)
- Change coupling: factory.rb ↔ trait.rb (lib/factory_bot/factory.rb)
- High CVE: [GHSA redacted] (Gemfile.lock)
- High CVE: [GHSA redacted] (Gemfile.lock)
- High: security finding (details withheld)
- High: security finding (details withheld)
- High: security finding (details withheld)
- High: security finding (details withheld)
- High: security finding (details withheld)
- High: security finding (details withheld)
- High: security finding (details withheld)
- High: security finding (details withheld)
- High: security finding (details withheld)
- High: security finding (details withheld)
- High: security finding (details withheld)
- High: security finding (details withheld)
- High: security finding (details withheld)
- High: security finding (details withheld)
- Inconsistent naming for existence/lookup checks. Attribute uses alias_for? which implies checking if an alias exists for a specific attribute, while Sequence uses has_name? and has_uri? which are generic existence checks. If alias_for? is meant to check if the attribute is an alias or has an alias, it differs from the explicit has_* pattern used in Sequence. More critically, Sequence exposes both has_name? and has_uri?, whereas Attribute only has alias_for?. If the intent is to check if a name/alias is registered, the naming convention is inconsistent across types.
- Low CVE: [GHSA redacted] (Gemfile.lock)
- …and 14 more
Changes since last survey
- 3 commits — 3 feature/other, 0 fixes
By area
- (root) — 1 commit
- spec/acceptance — 1 commit
- spec/factory_bot — 1 commit
Notable commits
- change: Expanded trait error message to include list of defined traits. (#1824)
- change: Fix typos in comments and documentation (#1823)
- change: Issue 1825 - Refactor internal references to ignored (attributes) to transient attributes (#1828)
Written by watchdog.canine.dev from the codebase's own history, inside the signed delivery this page is composed from.
Survey your own repository
thoughtbot/factory_bot was measured the same way every project in this corpus was: the same rubric, at a pinned commit, with the result published in full. Point a surveyor at a repository you know and see whether you agree with it.
About this page
- The score is its most recent published measurement, taken on 26 September 2026 at a pinned commit. It is not a live figure and does not change until the project is measured again.
- Measured at commit 18ae8b581bf55de681c8adb5f74d32787fd2157f — the exact code this score is about.
- Scored under rubric-2026.09.15 — the same rubric and the same method as every other entry in this index.
- Measured by watchdog.canine.dev using codehealth-analyzer preprod-d0929f7ac71f.