rubocop / rubocop-factory_bot

Code style checking for factory_bot files.
https://docs.rubocop.org/rubocop-factory_bot
MIT License
47 stars 13 forks source link

Cop idea: force ordering in factories #12

Open Darhazer opened 2 years ago

Darhazer commented 2 years ago

Given a factory bot definition, it would be nice to force some consistent structure:

Those could be separate cops of course

pirj commented 2 years ago

I'm on the fence regarding ordering, sometimes it's interleaved for better visibility:

role { :generic } # attribute
trait(:admin) do
  role { :admin }
end

tweaked_at { Time.current }

Speaking more broadly, and you know what I'm talking about by codename Ferrari, factories are the hottest pain point of testing. It's a shame there's no such thing as a factory_bot-style-guide. cc @AlexVKO. I'm always triggered with bad memories when seeing dreaded factories with multiple after(:create) { create(:assoc, ...) }.