Cucumber.Factory 项目技术文档
本文档旨在帮助用户安装、使用并详细了解 Cucumber.Factory 项目。以下是项目的主要内容:
1. 安装指南
在项目的 Gemfile 文件中添加以下代码:
gem 'cucumber_factory'
然后创建一个名为 features/step_definitions/factory_steps.rb 的文件,并在其中添加以下内容:
require 'cucumber_factory/add_steps'
接着运行以下命令安装依赖项并重启服务器:
bundle install
2. 项目的使用说明
Cucumber.Factory 允许用户直接从 Cucumber 特性文件中创建 ActiveRecord 对象,无需定义步骤。
基本用法
使用 Given there is 开头创建具有默认属性的新记录:
Given there is a movie
创建记录时,cucumber_factory 将根据可用选项调用 FactoryBot.create(:movie)、FactoryGirl.create(:movie)、Movie.make、Movie.create! 或 Movie.new。
使用引号字符串和数字表示属性值:
Given there is a movie with the title "Sunshine" and the year 2007
更新现有记录时,指定记录和更改内容:
Given the movie above has the title "Sunset" and the year 2008
Given the movie "Sunrise" has the year 2009
可以使用 above 关键字指定最近创建的记录,或使用创建时使用的任何字符串。
设置布尔属性
通过在末尾添加 which、that 或 who 来设置布尔属性:
Given there is a movie which is awesome
And there is a movie with the name "Sunshine" that is not a comedy
And there is a director who is popular
可以使用 and、but 或逗号连接句子:
Given there is a movie which is awesome, popular and successful but not science fiction
And there is a director with the income "500000" but with the account balance "-30000"
更新布尔属性时使用 is 关键字:
Given the movie above is awesome but not popular
Given the movie above has the year 1979 but is not science fiction
使用表格设置多个属性
如果有多个属性分配,可以使用文档字符串或数据表:
Given there is a movie with these attributes:
"""
name: Sunshine
comedy: false
"""
Given there is a movie with these attributes:
| name | Sunshine |
| comedy | false |
Given the movie above has these attributes:
"""
name: Sunshine
comedy: false
"""
设置关联
可以通过引用最后一个创建的记录作为 above 来设置 belongs_to 和 transient 关联:
Given there is a movie with the title "Before Sunrise"
And there is a movie with the prequel above
示例还展示了如何设置 has_many 关联 - 只需在另一侧设置 belongs_to 关联。
也可以使用创建时使用的任何字符串属性引用以前创建的记录:
Given there is a movie with the title "Before Sunrise"
And there is a movie with the title "Limitless"
And there is a movie with the prequel "Before Sunrise"
还可以显式给记录命名并使用它来在下面设置 belongs_to 关联:
Given "Before Sunrise" is a movie
And there is a movie with the title "Limitless"
And there is a movie with the prequel "Before Sunrise"
注意,在上面的示例中,"Before Sunrise" 仅是用于引用记录的名称。该名称不用于电影标题或其他属性值。
设置数组属性或 has_many 关联
可以通过引用多个命名记录来设置 has_many 关联:
Given there is a movie with the title "Sunshine"
And there is a movie with the title "Limitless"
And there is a movie with the title "Salt"
And there is a user with the favorite movies ["Sunshine", "Limitless" and "Salt"]
使用 PostgreSQL 数组列时,可以将数组属性设置为带方括号的值:
Given there is a movie with the tags ["comedy", "drama" and "action"]
设置文件属性
可以使用以下语法将属性设置为文件对象:
Given there is a movie with the image file:'path/to/image.jpg'
所有路径都是相对于项目根目录的,不支持绝对路径。请注意,文件属性必须遵循 file:"PATH" 语法,单引号和双引号都是允许的。
使用命名工厂和特性
可以使用 FactoryBot 子工厂或 Machinist 命名蓝图,将变体名称放在括号内:
Given there is a movie (comedy) with the title "Groundhog Day"
可以使用 FactoryBot 特性,将特性放在括号中,并用逗号分隔:
Given there is a movie (moody, dark) with the title "Interstellar"
覆盖工厂步骤
如果要覆盖工厂步骤的自定义版本,只需这样做:
Given /^there is a movie with good actors$/ do
movie = Movie.make
movie.actors << Actor.make(:name => 'Clive Owen')
movie.actors << Actor.make(:name => 'Denzel Washington')
end
自定义步骤将始终优先于工厂步骤。如果唯一其他匹配的步骤是工厂步骤,Cucumber 也不会发出关于模糊步骤的警告。感谢 cucumber_priority!
3. 项目 API 使用文档
Cucumber.Factory 的 API 使用主要涉及创建和更新 ActiveRecord 对象。以下是一些基本的使用示例:
- 创建新记录:
Given there is a movie
- 使用属性创建记录:
Given there is a movie with the title "Sunshine" and the year 2007
- 更新现有记录:
Given the movie above has the title "Sunset" and the year 2008
- 设置布尔属性:
Given there is a movie which is awesome
- 使用表格设置多个属性:
Given there is a movie with these attributes:
| name | Sunshine |
| comedy | false |
- 设置关联:
Given there is a movie with the prequel above
- 使用命名工厂和特性:
Given there is a movie (comedy) with the title "Groundhog Day"
4. 项目安装方式
请参考“安装指南”部分,安装方式如下:
- 在
Gemfile中添加gem 'cucumber_factory' - 创建
features/step_definitions/factory_steps.rb文件并添加require 'cucumber_factory/add_steps' - 运行
bundle install命令安装依赖项
以上是关于 Cucumber.Factory 项目的详细技术文档,希望对用户有所帮助。
ERNIE-4.5-VL-28B-A3B-ThinkingERNIE-4.5-VL-28B-A3B-Thinking 是 ERNIE-4.5-VL-28B-A3B 架构的重大升级,通过中期大规模视觉-语言推理数据训练,显著提升了模型的表征能力和模态对齐,实现了多模态推理能力的突破性飞跃Python00
unified-cache-managementUnified Cache Manager(推理记忆数据管理器),是一款以KV Cache为中心的推理加速套件,其融合了多类型缓存加速算法工具,分级管理并持久化推理过程中产生的KV Cache记忆数据,扩大推理上下文窗口,以实现高吞吐、低时延的推理体验,降低每Token推理成本。Python03
Kimi-K2-ThinkingKimi K2 Thinking 是最新、性能最强的开源思维模型。从 Kimi K2 开始,我们将其打造为能够逐步推理并动态调用工具的思维智能体。通过显著提升多步推理深度,并在 200–300 次连续调用中保持稳定的工具使用能力,它在 Humanity's Last Exam (HLE)、BrowseComp 等基准测试中树立了新的技术标杆。同时,K2 Thinking 是原生 INT4 量化模型,具备 256k 上下文窗口,实现了推理延迟和 GPU 内存占用的无损降低。Python00
Spark-Prover-X1-7BSpark-Prover-X1-7B is a 7B-parameter large language model developed by iFLYTEK for automated theorem proving in Lean4. It generates complete formal proofs for mathematical theorems using a three-stage training framework combining pre-training, supervised fine-tuning, and reinforcement learning. The model achieves strong formal reasoning performance and state-of-the-art results across multiple theorem-proving benchmarksPython00
MiniCPM-V-4_5MiniCPM-V 4.5 是 MiniCPM-V 系列中最新且功能最强的模型。该模型基于 Qwen3-8B 和 SigLIP2-400M 构建,总参数量为 80 亿。与之前的 MiniCPM-V 和 MiniCPM-o 模型相比,它在性能上有显著提升,并引入了新的实用功能Python00
Spark-Formalizer-X1-7BSpark-Formalizer-X1-7B is a 7B-parameter large language model by iFLYTEK for mathematical auto-formalization. It translates natural-language math problems into precise Lean4 formal statements, achieving high accuracy and logical consistency. The model is trained with a two-stage strategy combining large-scale pre-training and supervised fine-tuning for robust formal reasoning.Python00
GOT-OCR-2.0-hf阶跃星辰StepFun推出的GOT-OCR-2.0-hf是一款强大的多语言OCR开源模型,支持从普通文档到复杂场景的文字识别。它能精准处理表格、图表、数学公式、几何图形甚至乐谱等特殊内容,输出结果可通过第三方工具渲染成多种格式。模型支持1024×1024高分辨率输入,具备多页批量处理、动态分块识别和交互式区域选择等创新功能,用户可通过坐标或颜色指定识别区域。基于Apache 2.0协议开源,提供Hugging Face演示和完整代码,适用于学术研究到工业应用的广泛场景,为OCR领域带来突破性解决方案。00- HHowToCook程序员在家做饭方法指南。Programmer's guide about how to cook at home (Chinese only).Dockerfile015
Spark-Scilit-X1-13B科大讯飞Spark Scilit-X1-13B基于最新一代科大讯飞基础模型,并针对源自科学文献的多项核心任务进行了训练。作为一款专为学术研究场景打造的大型语言模型,它在论文辅助阅读、学术翻译、英语润色和评论生成等方面均表现出色,旨在为研究人员、教师和学生提供高效、精准的智能辅助。Python00- PpathwayPathway is an open framework for high-throughput and low-latency real-time data processing.Python00