{"id":13428111,"url":"https://github.com/thoughtbot/factory_bot_rails","last_synced_at":"2025-05-12T05:27:47.804Z","repository":{"id":40726111,"uuid":"683939","full_name":"thoughtbot/factory_bot_rails","owner":"thoughtbot","description":"Factory Bot ♥ Rails","archived":false,"fork":false,"pushed_at":"2025-02-28T15:16:07.000Z","size":402,"stargazers_count":3108,"open_issues_count":7,"forks_count":375,"subscribers_count":61,"default_branch":"main","last_synced_at":"2025-05-08T22:05:11.255Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://thoughtbot.com/services/ruby-on-rails","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/thoughtbot.png","metadata":{"files":{"readme":"README.md","changelog":"NEWS.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":"CODEOWNERS","security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"thoughtbot"}},"created_at":"2010-05-24T20:27:03.000Z","updated_at":"2025-05-05T17:18:23.000Z","dependencies_parsed_at":"2023-01-24T20:30:30.086Z","dependency_job_id":"e05dea5b-97b5-4302-9ad3-2bba8b939680","html_url":"https://github.com/thoughtbot/factory_bot_rails","commit_stats":{"total_commits":346,"total_committers":85,"mean_commits":4.070588235294117,"dds":0.7254335260115607,"last_synced_commit":"346e3c75c7a96616b32f8da95ebb1e027a9012d8"},"previous_names":["thoughtbot/factory_girl_rails"],"tags_count":57,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thoughtbot%2Ffactory_bot_rails","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thoughtbot%2Ffactory_bot_rails/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thoughtbot%2Ffactory_bot_rails/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thoughtbot%2Ffactory_bot_rails/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thoughtbot","download_url":"https://codeload.github.com/thoughtbot/factory_bot_rails/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253154974,"owners_count":21862622,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T01:00:46.459Z","updated_at":"2025-05-11T03:14:29.725Z","avatar_url":"https://github.com/thoughtbot.png","language":"Ruby","readme":"# factory_bot_rails [![Code Climate][grade-image]][grade] [![Gem Version][version-image]][version]\n\n[factory_bot][fb] is a fixtures replacement with a straightforward definition\nsyntax, support for multiple build strategies (saved instances, unsaved\ninstances, attribute hashes, and stubbed objects), and support for multiple\nfactories for the same class (`user`, `admin_user`, and so on), including factory\ninheritance.\n\n### Transitioning from factory\\_girl\\_rails?\n\nCheck out the [guide](https://github.com/thoughtbot/factory_bot/blob/4-9-0-stable/UPGRADE_FROM_FACTORY_GIRL.md).\n\n## Rails\n\nfactory\\_bot\\_rails provides Rails integration for [factory_bot][fb].\n\nSupported Rails versions are listed in [`Appraisals`](Appraisals). Supported\nRuby versions are listed in [`.github/workflows/build.yml`](.github/workflows/build.yml).\n\n## Download\n\nGithub: http://github.com/thoughtbot/factory_bot_rails\n\nGem:\n\n    $ gem install factory_bot_rails\n\n## Configuration\n\nAdd `factory_bot_rails` to your Gemfile in both the test and development groups:\n\n```ruby\ngroup :development, :test do\n  gem 'factory_bot_rails'\nend\n```\n\nYou may want to configure your test suite to include factory\\_bot methods; see\n[configuration](https://github.com/thoughtbot/factory_bot/blob/main/GETTING_STARTED.md#configure-your-test-suite).\n\n### Automatic Factory Definition Loading\n\nBy default, factory\\_bot\\_rails will automatically load factories\ndefined in the following locations,\nrelative to the root of the Rails project:\n\n```\nfactories.rb\ntest/factories.rb\nspec/factories.rb\nfactories/*.rb\ntest/factories/*.rb\nspec/factories/*.rb\n```\n\nYou can configure by adding the following to `config/application.rb` or the\nappropriate environment configuration in `config/environments`:\n\n```ruby\nconfig.factory_bot.definition_file_paths = [\"custom/factories\"]\n```\n\nThis will cause factory\\_bot\\_rails to automatically load factories in\n`custom/factories.rb` and `custom/factories/*.rb`.\n\nIt is possible to use this setting to share factories from a gem:\n\n```rb\nbegin\n  require 'factory_bot_rails'\nrescue LoadError\nend\n\nclass MyEngine \u003c ::Rails::Engine\n  config.factory_bot.definition_file_paths +=\n    [File.expand_path('../factories', __FILE__)] if defined?(FactoryBotRails)\nend\n```\n\nYou can also disable automatic factory definition loading entirely by\nusing an empty array:\n\n```rb\nconfig.factory_bot.definition_file_paths = []\n```\n\n### File Fixture Support\n\nFactories have access to [ActiveSupport::Testing::FileFixtures#file_fixture][]\nhelper to read files from tests.\n\nTo disable file fixture support, set `file_fixture_support = false`:\n\n```rb\nconfig.factory_bot.file_fixture_support = false\n```\n\n[ActiveSupport::Testing::FileFixtures#file_fixture]: https://api.rubyonrails.org/classes/ActiveSupport/Testing/FileFixtures.html#method-i-file_fixture\n\n### Generators\n\nIncluding factory\\_bot\\_rails in the development group of your Gemfile\nwill cause Rails to generate factories instead of fixtures.\nIf you want to disable this feature, you can either move factory\\_bot\\_rails out\nof the development group of your Gemfile, or add the following configuration:\n\n```ruby\nconfig.generators do |g|\n  g.factory_bot false\nend\n```\n\nIf fixture replacement is enabled and you already have a `test/factories.rb`\nfile (or `spec/factories.rb` if using rspec_rails), generated factories will be\ninserted at the top of the existing file.\nOtherwise, factories will be generated in the\n`test/factories` directory (`spec/factories` if using rspec_rails),\nin a file matching the name of the table (e.g. `test/factories/users.rb`).\n\nTo generate factories in a different directory, you can use the following\nconfiguration:\n\n```ruby\nconfig.generators do |g|\n  g.factory_bot dir: 'custom/dir/for/factories'\nend\n```\n\nNote that factory\\_bot\\_rails will not automatically load files in custom\nlocations unless you add them to `config.factory_bot.definition_file_paths` as\nwell.\n\nThe suffix option allows you to customize the name of the generated file with a\nsuffix:\n\n```ruby\nconfig.generators do |g|\n  g.factory_bot suffix: \"factory\"\nend\n```\n\nThis will generate `test/factories/users_factory.rb` instead of\n`test/factories/users.rb`.\n\nFor even more customization, use the `filename_proc` option:\n\n```ruby\nconfig.generators do |g|\n  g.factory_bot filename_proc: -\u003e(table_name) { \"prefix_#{table_name}_suffix\" }\nend\n```\n\nTo override the [default factory template][], define your own template in\n`lib/templates/factory_bot/model/factories.erb`. This template will have\naccess to any methods available in `FactoryBot::Generators::ModelGenerator`.\nNote that factory\\_bot\\_rails will only use this custom template if you are\ngenerating each factory in a separate file; it will have no effect if you are\ngenerating all of your factories in `test/factories.rb` or `spec/factories.rb`.\n\nFactory\\_bot\\_rails will add a custom generator:\n\n```shell\nrails generate factory_bot:model NAME [field:type field:type] [options]\n```\n\n[default factory template]: https://github.com/thoughtbot/factory_bot_rails/tree/main/lib/generators/factory_bot/model/templates/factories.erb\n\n## Contributing\n\nPlease see [CONTRIBUTING.md](CONTRIBUTING.md).\n\nfactory_bot_rails was originally written by Joe Ferris and is maintained by thoughtbot. Many improvements and bugfixes were contributed by the [open source\ncommunity](https://github.com/thoughtbot/factory_bot_rails/graphs/contributors).\n\n## License\n\nfactory_bot_rails is Copyright © 2008 Joe Ferris and thoughtbot. It is free\nsoftware, and may be redistributed under the terms specified in the\n[LICENSE](LICENSE) file.\n\n\u003c!-- START /templates/footer.md --\u003e\n## About thoughtbot\n\n![thoughtbot](https://thoughtbot.com/thoughtbot-logo-for-readmes.svg)\n\nThis repo is maintained and funded by thoughtbot, inc.\nThe names and logos for thoughtbot are trademarks of thoughtbot, inc.\n\nWe love open source software!\nSee [our other projects][community].\nWe are [available for hire][hire].\n\n[community]: https://thoughtbot.com/community?utm_source=github\n[hire]: https://thoughtbot.com/hire-us?utm_source=github\n\n\u003c!-- END /templates/footer.md --\u003e\n\n[fb]: https://github.com/thoughtbot/factory_bot\n[grade]: https://codeclimate.com/github/thoughtbot/factory_bot_rails\n[grade-image]: https://codeclimate.com/github/thoughtbot/factory_bot_rails.svg\n[community]: https://thoughtbot.com/community?utm_source=github\n[hire]: https://thoughtbot.com/hire-us?utm_source=github\n[version-image]: https://badge.fury.io/rb/factory_bot_rails.svg\n[version]: https://badge.fury.io/rb/factory_bot_rails\n[hound-image]: https://img.shields.io/badge/Reviewed_by-Hound-8E64B0.svg\n[hound]: https://houndci.com\n","funding_links":["https://github.com/sponsors/thoughtbot"],"categories":["Testing","Ruby","Gherkin","Gems"],"sub_categories":["Omniauth","Testing","Articles"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthoughtbot%2Ffactory_bot_rails","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthoughtbot%2Ffactory_bot_rails","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthoughtbot%2Ffactory_bot_rails/lists"}