[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-7873":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":9,"htmlUrl":10,"language":11,"languages":10,"totalLinesOfCode":10,"stars":12,"forks":13,"watchers":14,"openIssues":15,"contributorsCount":16,"subscribersCount":16,"size":16,"stars1d":16,"stars7d":17,"stars30d":18,"stars90d":16,"forks30d":16,"starsTrendScore":16,"compositeScore":19,"rankGlobal":10,"rankLanguage":10,"license":20,"archived":21,"fork":21,"defaultBranch":22,"hasWiki":21,"hasPages":21,"topics":23,"createdAt":10,"pushedAt":10,"updatedAt":24,"readmeContent":25,"aiSummary":26,"trendingCount":16,"starSnapshotCount":16,"syncStatus":27,"lastSyncTime":28,"discoverSource":29},7873,"factory_bot_rails","thoughtbot\u002Ffactory_bot_rails","thoughtbot","Factory Bot ♥ Rails","https:\u002F\u002Fthoughtbot.com\u002Fservices\u002Fruby-on-rails",null,"Ruby",3137,375,58,4,0,1,14,61.63,"MIT License",false,"main",[],"2026-06-12 04:00:36","# 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:\u002F\u002Fgithub.com\u002Fthoughtbot\u002Ffactory_bot\u002Fblob\u002F4-9-0-stable\u002FUPGRADE_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\u002Fworkflows\u002Fbuild.yml`](.github\u002Fworkflows\u002Fbuild.yml).\n\n## Download\n\nGithub: http:\u002F\u002Fgithub.com\u002Fthoughtbot\u002Ffactory_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:\u002F\u002Fgithub.com\u002Fthoughtbot\u002Ffactory_bot\u002Fblob\u002Fmain\u002FGETTING_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\u002Ffactories.rb\nspec\u002Ffactories.rb\nfactories\u002F*.rb\ntest\u002Ffactories\u002F*.rb\nspec\u002Ffactories\u002F*.rb\n```\n\nYou can configure by adding the following to `config\u002Fapplication.rb` or the\nappropriate environment configuration in `config\u002Fenvironments`:\n\n```ruby\nconfig.factory_bot.definition_file_paths = [\"custom\u002Ffactories\"]\n```\n\nThis will cause factory\\_bot\\_rails to automatically load factories in\n`custom\u002Ffactories.rb` and `custom\u002Ffactories\u002F*.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('..\u002Ffactories', __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:\u002F\u002Fapi.rubyonrails.org\u002Fclasses\u002FActiveSupport\u002FTesting\u002FFileFixtures.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\u002Ffactories.rb`\nfile (or `spec\u002Ffactories.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\u002Ffactories` directory (`spec\u002Ffactories` if using rspec_rails),\nin a file matching the name of the table (e.g. `test\u002Ffactories\u002Fusers.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\u002Fdir\u002Ffor\u002Ffactories'\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\u002Ffactories\u002Fusers_factory.rb` instead of\n`test\u002Ffactories\u002Fusers.rb`.\n\nFor even more customization, use the `filename_proc` option:\n\n```ruby\nconfig.generators do |g|\n  g.factory_bot filename_proc: ->(table_name) { \"prefix_#{table_name}_suffix\" }\nend\n```\n\nTo override the [default factory template][], define your own template in\n`lib\u002Ftemplates\u002Ffactory_bot\u002Fmodel\u002Ffactories.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\u002Ffactories.rb` or `spec\u002Ffactories.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:\u002F\u002Fgithub.com\u002Fthoughtbot\u002Ffactory_bot_rails\u002Ftree\u002Fmain\u002Flib\u002Fgenerators\u002Ffactory_bot\u002Fmodel\u002Ftemplates\u002Ffactories.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:\u002F\u002Fgithub.com\u002Fthoughtbot\u002Ffactory_bot_rails\u002Fgraphs\u002Fcontributors).\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 \u002Ftemplates\u002Ffooter.md -->\n## About thoughtbot\n\n![thoughtbot](https:\u002F\u002Fthoughtbot.com\u002Fthoughtbot-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:\u002F\u002Fthoughtbot.com\u002Fcommunity?utm_source=github\n[hire]: https:\u002F\u002Fthoughtbot.com\u002Fhire-us?utm_source=github\n\n\u003C!-- END \u002Ftemplates\u002Ffooter.md -->\n\n[fb]: https:\u002F\u002Fgithub.com\u002Fthoughtbot\u002Ffactory_bot\n[grade]: https:\u002F\u002Fcodeclimate.com\u002Fgithub\u002Fthoughtbot\u002Ffactory_bot_rails\n[grade-image]: https:\u002F\u002Fcodeclimate.com\u002Fgithub\u002Fthoughtbot\u002Ffactory_bot_rails.svg\n[community]: https:\u002F\u002Fthoughtbot.com\u002Fcommunity?utm_source=github\n[hire]: https:\u002F\u002Fthoughtbot.com\u002Fhire-us?utm_source=github\n[version-image]: https:\u002F\u002Fbadge.fury.io\u002Frb\u002Ffactory_bot_rails.svg\n[version]: https:\u002F\u002Fbadge.fury.io\u002Frb\u002Ffactory_bot_rails\n[hound-image]: https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FReviewed_by-Hound-8E64B0.svg\n[hound]: https:\u002F\u002Fhoundci.com\n","thoughtbot\u002Ffactory_bot_rails 是一个用于 Ruby on Rails 项目的工厂模式库，旨在替代传统的固定数据集（fixtures）。其核心功能包括直观的定义语法、多种构建策略支持（如保存实例、未保存实例、属性哈希和存根对象）以及对同一类别的多个工厂的支持（例如 user 和 admin_user），并且允许工厂继承。该工具特别适用于需要灵活创建测试数据的 Rails 应用场景，能够显著提高开发者编写测试代码时的效率与灵活性。此外，它还提供了自动加载工厂定义文件的功能，使得配置更加便捷。",2,"2026-06-11 03:14:50","top_language"]