gpt4 book ai didi

ruby-on-rails - FactoryBot 获取工厂的可用特征

转载 作者:数据小太阳 更新时间:2023-10-29 07:33:19 25 4
gpt4 key购买 nike

是否有 FactoryBot 方法或某种方式来获取工厂的可用特征?

例如:

FactoryBot.define do
factory :address, class: Address do
trait :in_california do
state 'CA'
end

trait :in_new_york do
state 'NY'
end

trait :in_florida do
state 'FL'
end
end

我希望能够以编程方式获取特征,例如 FactoryBot.get_traits (:address),它将返回为该工厂定义的特征数组,在本例中为

["in_california", "in_new_york", "in_florida"]

这样是不是更清楚了?

最佳答案

我相信你想要的是以下内容:

FactoryBot.factories[:address].defined_traits.map(&:name)
#=> ["in_california", "in_new_york", "in_florida"]

关于ruby-on-rails - FactoryBot 获取工厂的可用特征,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51563889/

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