A fixtures replacement library for Rails testing with a straightforward definition syntax and multiple build strategies.
factory_bot_rails is a Ruby gem that integrates factory_bot with Ruby on Rails applications. It provides a fixtures replacement system for creating test data with a clean, expressive syntax, replacing Rails' traditional fixture system. The library helps developers build and maintain test data factories that automatically integrate with Rails' conventions and generators.
Rails developers who write tests and need a maintainable way to create test data, particularly those using RSpec, Minitest, or other Ruby testing frameworks within Rails applications.
Developers choose factory_bot_rails because it seamlessly integrates factory_bot's powerful test data creation capabilities with Rails conventions, offering automatic factory loading, generator support, and file fixture integration out of the box. It reduces boilerplate and makes test data management consistent across Rails projects.
Factory Bot ♥ Rails
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Automatically loads factories from conventional directories like test/factories and integrates with Rails generators, reducing boilerplate as per the Configuration section.
Supports multiple strategies including saved instances, unsaved instances, attribute hashes, and stubbed objects, enabling precise test data control as highlighted in the README.
Allows defining multiple factories for the same class with inheritance, promoting DRY code and shared attributes, a core feature described in the README.
Replaces Rails fixture generation with factory creation when models are generated, streamlining workflow and adhering to Rails conventions.
Factory instantiation adds abstraction layers that can slow down test execution compared to direct object creation or raw fixtures, a trade-off for flexibility.
Requires setup for definition paths, file fixture support, and generator options, which can be cumbersome in complex Rails applications, as noted in the Configuration section.
Specifically designed for Rails, so it cannot be used in non-Rails Ruby projects, limiting portability and flexibility in mixed environments.