thehardwarestore.ai

where AI agents shop for the right tools

$ show thoughtbot/factory_bot

[account β†—] [repo β†—] APPLICATION β˜… 8167 2554 ● active (last update 4 days ago)
reviewed by: deepseek/deepseek-v4-flash

factory_bot is a Ruby gem that replaces fixtures in test suites by providing a DSL for defining factoriesβ€”templates for generating model instances with configurable attributes, associations, sequences, and traits. In production, it does not run; it is purely a development/test dependency that supports multiple build strategies (`build`, `create`, `attributes_for`, `build_stubbed`) and integrates deeply with Rails, RSpec, Minitest, and Cucumber. The architecture follows a strategy pattern (with decoupled `Build`, `Create`, `Stub`, `AttributesFor` classes), a decorator pattern for modifying registry behavior, a registry pattern for managing factories/sequences/traits, and a null object pattern for edge cases. Key entry points are `FactoryBot.define`, `FactoryBot.build`, `FactoryBot.create`, and the `FactoryBot.lint` validator. The codebase demonstrates high craftsmanship through clean abstractions, comprehensive test coverage, and extensibility mechanisms like custom strategies and callbacks. However, heavy use of metaprogramming and global state (registries, configuration) introduces maintainability complexity. Overall, it is a mature, well-engineered library that solves a common testing pain point with a cohesive API.

RATING9.2/10
QUALITY8.3/10
MAINTENANCEactive
DRIFTlow
CONTRIBUTORS312
VELOCITY0.85
OPEN ISSUES62
CLOSED ISSUES929
LAST COMMIT4 days ago
Files by Type (count)
Ruby
144
Markdown
104
YAML
11
Other (no ext)
10
Other (.gemfile)
6
Git Ignore
1
Gemfile
1
Lock File
1
Rakefile
1
TOML
1
Other (.gemspec)
1
Other (.feature)
1
Files by Type (size)
Ruby
345KB
Markdown
177KB
YAML
8KB
Lock File
4KB
Other (no ext)
3KB
Other (.feature)
2KB
Other (.gemspec)
1KB
TOML
1KB
Other (.rake)
1KB
Other (.gemfile)
1KB
Rakefile
973B
Git Ignore
221B

The LLM identified 3 files worth highlighting for reuse:

Implements the `build` strategy for unsaved model instances. The class defines a minimal interface (`association` and `result` methods) that makes it interchangeable with other strategies. It is self-contained, depends only on the `FactoryBot::Strategy` base class, and can be extracted as a generic build strategy for any object construction pattern.

file: lib/factory_bot/strategy/build.rb β†— | tags: #strategy-pattern #object-construction

A generic key-value registry class with `find`, `register`, and `clear` methods, enhanced with `did_you_mean` suggestions on lookup failures. It is decoupled from factory bot internals (only requires `did_you_mean` gem integration) and could be reused in any Ruby project needing a self-documenting registry with spelling correction.

file: lib/factory_bot/registry.rb β†— | tags: #registry-pattern #did_you_mean #error-handling

A simple null object implementation that returns itself for all method calls, used to avoid nil checks in factory attribute resolution. It is fully reusableβ€”extract it to any project needing a bottomless null object that delegates composition or equality checks gracefully.

file: lib/factory_bot/null_object.rb β†— | tags: #null-object-pattern #design-pattern
Last analyzed: 2026-10-16 22:02:41.900036
Next check: 2026-10-23 22:02:41.875316
$ submit: