Is there a FactoryBot method or some way to get available traits for a factory?
Ex:
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
I want to be able to get the traits programatically, something like FactoryBot.get_traits (:address) and it would return an array of the traits defined for that factory, in this case that would be
["in_california", "in_new_york", "in_florida"]
Does that make it clearer?
attributes_for(:my_factory).keys
will return only the keys from the hash of attributes defined in the factory ':user' – WoadFactoryBot.factories
orFactoryBot.traits
. You can also take a look at FactoryBot.configuration.factories[:your_factory].defined_traits – Woad