factory_bot
factory_bot copied to clipboard
How to mark traits or factories as deprecated?
Problem this feature will solve
When working on a large codebase with factories (or traits in my case) that have common names, it's hard to grep/find all usages of it and update the specs.
Desired solution
It would be a good approach to have a way to mark a trait or factory as deprecated and raise a depreciation warning every time it is used.
Alternatives considered
I'm going to look into observers, maybe it can be used here. Not sure if I will be able to pinpoint where the factory was used though.
Additional context
Would something like this work for you?
FactoryBot.define do
factory :something do
trait :trait_to_be_deprecated do
# Whatever the trait does
after(:build) { # print deprecation or raise }
end
end
end
Or if you want to be fancy you might be able to make a trait for deprecating traits (although I recall trait inheritance getting weird sometimes):
FactoryBot.define do
trait :deprecated do
after(:build) { # print deprecation or raise }
end
factory :something do
trait :trait_to_be_deprecated do
deprecated
end
trait :another_deprecated_trait do
deprecated
end
end
factory :something_else do
trait :trait_to_be_deprecated do
deprecated
end
end
end