// the find
thoughtbot/factory_bot
A library for setting up Ruby objects as test data.
factory_bot is the de-facto standard for generating test data in Ruby/Rails. It replaces static fixtures with programmatic factory definitions, supporting multiple build strategies (create, build, build_stubbed, attributes_for) and a flexible trait/inheritance system. If you're writing Rails tests, you're almost certainly using this or have recently migrated to it.
The build_stubbed strategy is genuinely clever — it creates stub objects without hitting the database at all, which keeps unit tests fast without requiring you to manage fixtures or mocks by hand. Traits compose well: you can stack multiple traits on a single create call and they resolve attribute precedence predictably. The linter (FactoryBot.lint) actively catches factories that fail to build, which surfaces broken factories before your test suite does it one test at a time. Documentation is unusually complete — the mdBook at thoughtbot.github.io/factory_bot covers edge cases like interconnected associations and polymorphic setups that would otherwise require reading the source.
Factory inheritance and traits interact in ways that surprise people: a child factory's trait can silently override a parent trait's attribute without any warning, and debugging attribute resolution requires knowing the internal declaration merge order. The create strategy hits the database by default, so test suites that lean on it heavily get slow — and teams often don't notice until they have thousands of examples. build_stubbed has real limits: anything that calls save!, runs callbacks touching the database, or uses ActiveRecord scopes will blow up at runtime, not at definition time. There's no built-in way to detect factories that create far more records than intended (e.g., a factory that pulls in five associations each creating their own associations) — FactoryTrace is a third-party add-on for this, not something factory_bot warns you about itself.