登录 注册
开发者工具效率与办公工具图像、视频与音频 factoriesfactory-botfactory-girlfixturesrailsruby
8,167
Stars
2,549
Forks
121
Watchers
63
Open Issues
MIT
许可证
Ruby
语言
2008-06-03
创建时间
2026-11-03
最近更新

项目能做什么

用于将 Ruby 对象设置为测试数据的库。
来源:AI 基于仓库事实生成 · 内容以仓库实际 README 为准

使用说明 查看原始 README 原仓库文档

中文使用说明暂未生成。下面保留原仓库 README 摘录,命令与配置均以原文为准。
原始 README 摘录(英文原文,节选前 3000 字符)
# factory_bot 

[![Build Status][ci-image]][ci] [![Gem Version][version-image]][version]

factory_bot is a fixtures replacement with a straightforward definition syntax, support for multiple build strategies (saved instances, unsaved instances, attribute hashes, and stubbed objects), and support for multiple factories for the same class (user, admin_user, and so on), including factory inheritance.

If you want to use factory_bot with Rails, see
[factory_bot_rails](https://github.com/thoughtbot/factory_bot_rails).

Interested in the history of the project name? You can find the history [here](https://github.com/thoughtbot/factory_bot/blob/main/NAME.md)

## Documentation

See our extensive reference, guides, and cookbook in [the factory_bot book][].

For information on integrations with third party libraries, such as RSpec or
Rails, see [the factory_bot wiki][].

 We also have [a detailed introductory video][], available for free on Upcase.

[a detailed introductory video]: https://upcase.com/videos/factory-bot?utm_source=github&utm_medium=open-source&utm_campaign=factory-girl
[the factory_bot book]: https://thoughtbot.github.io/factory_bot
[the factory_bot wiki]: https://github.com/thoughtbot/factory_bot/wiki

## Install

Run:

```ruby
bundle add factory_bot
```

To install the gem manually from your shell, run:

```shell
gem install factory_bot
```

## Supported Ruby versions

Supported Ruby versions are listed in `.github/workflows/build.yml` ([source](https://github.com/thoughtbot/factory_bot/blob/main/.github/workflows/build.yml))

## More Information

* [Rubygems](https://rubygems.org/gems/factory_bot)
* [Stack Overflow](https://stackoverflow.com/questions/tagged/factory-bot)
* [Issues](https://github.com/thoughtbot/factory_bot/issues)
* [GIANT ROBOTS SMASHING INTO OTHER GIANT ROBOTS](https://robots.thoughtbot.com/)

[GETTING_STARTED]: https://github.com/thoughtbot/factory_bot/blob/main/GETTING_STARTED.md

## Useful Tools

* [FactoryTrace](https://github.com/djezzzl/factory_trace) - helps to find unused factories and traits.
* [ruby-lsp-factory_bot](https://github.com/donny741/ruby-lsp-factory_bot) / [ruby-lsp-rails-factory-bot](https://github.com/johansenja/ruby-lsp-rails-factory-bot) - integration with [ruby-lsp](https://github.com/Shopify/ruby-lsp) to provide intellisense

Contributing
------------

Please see [CONTRIBUTING.md](https://github.com/thoughtbot/factory_bot/blob/main/CONTRIBUTING.md).

factory_bot was originally written by Joe Ferris and is maintained by thoughtbot.
Many improvements and bugfixes were contributed by the [open source
community](https://github.com/thoughtbot/factory_bot/graphs/contributors).

License
-------

factory_bot is Copyright © 2008 Joe Ferris and thoughtbot. It is free
software, and may be redistributed under the terms specified in the
[LICENSE] file.

[LICENSE]: https://github.com/thoughtbot/factory_bot/blob/main/LICENSE

<!-- START /templates/footer.md -->
## About thoughtbot

![thoughtbot](https://tho
阅读完整原文

商业机会分析 AI 生成

Rails 测试效能诊断与 Factory 级联创建检测工具

产品构想构建与 CI 集成的分析工具,专门检测因 factory_bot 滥用 `create` 或过度嵌套关联导致的数据库冗余写入与测试变慢问题,并给出 `build_stubbed` 优化建议。
核心功能CI 运行期数据捕获 Gem、Factory 依赖拓扑图解析、冗余 DB 写入耗时排名、一键自动重构/替换建议 PR 生成。
目标用户大型 Rails 单体应用团队、负责 CI/CD 效能的 Tech Lead。
难度/周期中等 · 1-2 个月 · 成本:极低(主要是 CI 测试基础设施与开发成本)
收费模式SaaS 订阅(按 CI 构建次数或私有代码库数量月费订阅)。
竞争风险开源社区存在轻量分析工具(如 factory_trace、test-prof),需在“自动修复建议”与“易用性”上建立足够高的价值壁垒。
依据 已验证事实

基于 IDE / Ruby-LSP 的企业级 Factory 可视化与关系分析插件

产品构想针对包含成百上千个 factory 和 trait 的大型项目,提供直观的图谱查看、死工厂检测、字段冲突高亮与高级补全。
核心功能Factory 继承与 Trait 依赖关系图可视化、未使用的 Factory/Trait 标记、基于 Schema 变更的自动校验与警告、跨文件快速跳转。
目标用户日常维护复杂 Rails 项目的中高级开发者与团队。
难度/周期中等 · 1 个月 · 成本:开发机器与少量测试用例开销
收费模式Freemium 模式(基础补全免费,依赖拓扑与健康检查收取单人年费或团队授权)。
竞争风险部分功能可能被 Shopify 官方 ruby-lsp 生态或 RubyMine 原生吸收。
依据 AI推测

AI 辅助的 Rails 模型到 Factory 自动化生成与重构代理

产品构想解析 ActiveRecord 模型验证、关联关系及生产脱敏数据,自动生成符合业务约束的高质量 factory_bot 定义,并随数据库迁移自动同步演进。
核心功能ActiveRecord 校验规则自动映射为 Factory/Trait、生产匿名数据特征逆向生成、Schema 迁移后自动修复失效 Factory、CLI 与 GitHub App 集成。
目标用户需要补齐遗留系统测试覆盖率的团队、外包重构工程团队。
难度/周期较高 · 2-3 个月 · 成本:LLM API 调用成本、云函数部署成本
收费模式按使用量(调用 Token 或分析代码行数)计费或企业席位制订阅。
竞争风险复杂的自定义业务验证规则难以通过静态 AST 或简单 LLM 提示词完美覆盖,生成代码可能存在语法或逻辑错误。
依据 尚需验证的假设
AI 基于仓库公开数据分析生成,含推测成分,不构成收益承诺。
报告会保存到 个人中心

竞品与相似项目 GitHub Search 真实检索

项目中文简介Stars语言
cathrynlavery/diagram-design 中文介绍暂未生成
Editorial diagram design for Claude Code, Codex, GitHub Copi
66,506 HTML
superplanehq/superplane 中文介绍暂未生成
Open source factory for one-shot engineering
10,028 Go
Kozea/WeasyPrint 中文介绍暂未生成
The awesome document factory
9,781 Python
projectstorm/react-diagrams 中文介绍暂未生成
a super simple, no-nonsense diagramming library written in r
9,438 TypeScript
SwanHubX/SwanLab 中文介绍暂未生成
⚡️SwanLab - an open-source, modern-design AI training tracki
4,374 Python
agent-of-empires/agent-of-empires 中文介绍暂未生成
Manage multiple Claude Code, OpenCode agents from either TUI
4,140 Rust
以上为通过 GitHub 官方 Search API 检索的相似项目,功能差异与优劣势需进一步人工确认,配置 AI 后可生成对比分析。

项目优势与风险

技术成熟度创建于 2008-06-03,近 30 天仍在推送,发布过 33 个 Release
社区活跃Star 8,167 / Fork 2,549 / Issue 63(数据支持,可自行核实)
许可证MIT
主要风险上游项目方向可能变化;同赛道竞争者较多(见竞品表);热度与需求不完全等价

安装与使用

快速开始(以仓库 README 为准)
git clone https://github.com/thoughtbot/factory_bot.git
cd factory_bot
# 请阅读仓库 README 获取确切安装步骤(依赖、配置、启动命令)
阅读原仓库文档
术语说明:Docker=应用容器(把程序和依赖打包运行);API Key=调用外部服务的密钥;Git Clone=把仓库代码下载到本地。常见错误:API Key 未配置 / 端口占用 / 数据库连接失败,多数项目在 README 的 Troubleshooting 章节有说明。