【发布时间】:2015-04-05 08:48:25
【问题描述】:
我正在考虑将许多模拟从 FactoryGirl 迁移到 Fabrication gem。
但是,到目前为止,我还没有找到任何有关实现 FactoryGirl 中可用的 trait 模式的信息。
是否有一种普遍接受的方法来使用 Fabrication 执行此操作?
提前感谢您提供任何答案或信息。
【问题讨论】:
标签: ruby-on-rails mocking factory-bot fabrication-gem
我正在考虑将许多模拟从 FactoryGirl 迁移到 Fabrication gem。
但是,到目前为止,我还没有找到任何有关实现 FactoryGirl 中可用的 trait 模式的信息。
是否有一种普遍接受的方法来使用 Fabrication 执行此操作?
提前感谢您提供任何答案或信息。
【问题讨论】:
标签: ruby-on-rails mocking factory-bot fabrication-gem
Fabrication 没有特征的语法糖。据我了解,这只是一种分组和定义继承的方式。
以这个工厂为例:(我从this blog post 中提取)
FactoryGirl.define do
factory :todo_item, aliases: [:incomplete_todo_item] do
name 'Pick up a gallon of milk'
complete false
factory :complete_todo_item do
complete true
end
end
end
你会在 Fabrication 中做同样的事情:
Fabricator(:todo_item, aliases: :incomplete_todo_item) do
name 'Pick up a gallon of milk'
complete false
end
Fabricator(:complete_todo_item, from: :todo_item) do
complete true
end
如果您决定转换,您可以发送至mailing list 并提出任何具体问题。我总是很乐意帮助您弄清楚如何让事情正常进行或提高制造商的效率。
【讨论】: