英文:
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 }
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论