提供FactoryBot中的单词白名单。

huangapple go评论125阅读模式
英文:

Provide a whitelist of words in FactoryBot

问题

我有一个工厂定义,看起来像这样:

FactoryBot.define do
  factory :foo do
    name { Faker::Lorem.word }
  end
end

我可以提供一个自定义的单词列表,这样名称始终会是我选择的单词之一吗?

英文:

I have a factory definition that looks like this:

FactoryBot.define do
  factory :foo do
    name { Faker::Lorem.word }
  end
end

Can I provide a custom list of words, so that the name is always going to be one of the words I choose?

答案1

得分: 2

name { ['my', 'words', ...].sample }

英文:

If you have a different set of words than what Faker::Lorem might offer then you could simply use that;

name { ['my', 'words', ...].sample }

huangapple
  • 本文由 发表于 2023年3月7日 20:15:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/75661857.html
  • factory-bot
  • ruby-on-rails