gpt4 book ai didi

ruby-on-rails - 如何实现 :with_trait using Fabrication

转载 作者:行者123 更新时间:2023-12-04 06:10:49 25 4
gpt4 key购买 nike

我正在考虑将许多模拟从 FactoryGirl 迁移到 Fabrication gem。

但是,到目前为止,我一直无法找到有关实现 的任何信息。性状 FactoryGirl 中可用的模式。

有没有一种普遍接受的方法来使用 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有任何具体问题。我总是很乐意帮助弄清楚如何让事情正常工作或提高制造商的效率。

关于ruby-on-rails - 如何实现 :with_trait using Fabrication,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29455605/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com