FactoryBot.define do
factory :user do
transient do
skills_count { 1 }
end
name { "foo" }
skills do
types = [:java, :go, :python]
(0..(skills_count - 1)).map do |i|
build(:skill, types[i % types.size])
end
end
end
factory :skill do
trait :java do
skill_name: { "java" }
end
...
end
end
FactoryBot.build(:user, skills_count: 3)