Generated by GPT-5-mini| Factory Bot | |
|---|---|
| Name | Factory Bot |
| Developer | thoughtbot |
| Released | 2010s |
| Programming language | Ruby (programming language) |
| Operating system | Cross-platform software |
| License | MIT License |
Factory Bot
Factory Bot is a Ruby library used to create test data for automated tests in Ruby on Rails applications and other Ruby (programming language) projects. It provides a declarative DSL for defining factories that generate instances of Ruby objects, replacing repetitive setup code in test suites that use frameworks such as RSpec (software), Minitest, and Cucumber (software). The library is maintained by contributors associated with thoughtbot, and is widely adopted across open-source and proprietary codebases, including many projects hosted on GitHub and deployed with Capistrano or continuous integration on Travis CI and CircleCI.
Factory Bot supplies a set of factory definitions that produce objects such as Active Record models in Ruby on Rails or plain Ruby objects for service objects and POROs. It complements testing tools like RSpec (software), Minitest, and Cucumber (software) by reducing duplication and improving readability of test setup within projects that often integrate with Active Record, Sequel (software), or repository patterns used by teams following Test-driven development. The DSL supports traits, sequences, and associations so factories can express relationships used in applications following patterns advocated by practitioners associated with thoughtbot and educators at conferences such as RailsConf and RubyConf.
Factory Bot originated as an evolution of earlier fixture and factory libraries in the Ruby ecosystem, responding to limitations of static fixtures used in Ruby on Rails applications. Early influences included libraries like Fixture Replacement tools and community projects documented in repositories on GitHub and discussed at events like RailsConf and RubyConf. The project was stewarded by developers at thoughtbot and grew through contributions from maintainers and community members who filed issues and pull requests referencing practices in Test-driven development, continuous integration platforms such as Travis CI and CircleCI, and development workflows used in startups and enterprises. Over time, Factory Bot added features to support multiple ORMs (e.g., Active Record, Sequel (software)) and to interoperate with test suites written for RSpec (software), Minitest, and acceptance testing with Cucumber (software).
Factory Bot centers on factories, traits, sequences, and associations. A factory definition declares how to build or create instances of a class, commonly an Active Record model such as User (computer system), Post (magazine), or Comment (comment), though the pattern is also used for POROs. Traits allow composition of shared behavior across multiple factories, mirroring patterns discussed by speakers at RailsConf and in blog posts hosted on GitHub Pages and tech blogs by consultancies like thoughtbot. Sequences provide deterministic unique values for attributes such as email addresses or slugs, which aligns with test isolation practices promoted in Test-driven development literature and workshops at RubyConf. Associations let factories express relationships between objects that reflect database associations created with Active Record macros or Sequel (software) associations used in projects showcased on GitHub.
Factory Bot includes features such as build strategies (build, create, attributes_for), callbacks (after(:create), before(:build)), and factory inheritance, which parallel techniques used in examples from RSpec (software) documentation and testing guides by community educators. Configuration allows setting default strategies, linting factories in test setup, and integrating with database cleaning approaches discussed alongside tools like Database Cleaner (software). Factory Bot supports custom sequences, transient attributes for temporary values, and lazy attributes evaluated at build time—patterns echoed in tutorials linked from GitHub repositories and conference talks by maintainers from organisations like thoughtbot.
Factory Bot integrates closely with RSpec (software), providing helper methods and RSpec configuration hooks to simplify usage in spec files and shared examples presented in many GitHub open-source projects. It also works with Minitest adapters and can be used in acceptance tests written for Cucumber (software). CI pipelines using Travis CI, CircleCI, or self-hosted runners for GitHub Actions commonly include Factory Bot in their test matrices for Rails applications, mirroring examples from continuous integration guides and blog posts by teams at thoughtbot and other consultancies. Integration patterns often reference database strategies employed in Rails applications that use Active Record or alternative ORMs such as Sequel (software).
The Factory Bot ecosystem comprises contributors on GitHub, documentation in READMEs and wikis, and community discussions on platforms such as Stack Overflow, Ruby Forum, and mailing lists tied to Ruby and Ruby on Rails. Many open-source Rails engines and applications include factory definitions in their test suites, visible in repositories on GitHub and showcased in tutorials from communities like thoughtbot and speakers at RailsConf and RubyConf. Ecosystem tools include adapters, linting helpers, and integrations with test helpers from RSpec (software), Capybara (software), and database management utilities discussed in posts by teams using Capistrano for deployment and CI configurations on Travis CI and CircleCI.
Category:Ruby libraries