Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cop idea: force ordering in factories #12

Open
Darhazer opened this issue Sep 23, 2022 · 1 comment
Open

Cop idea: force ordering in factories #12

Darhazer opened this issue Sep 23, 2022 · 1 comment
Labels

Comments

@Darhazer
Copy link
Member

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

  • alphabetical attribute ordering. Note that we should recognise FactoryBot methods (transient, association, trait, etc.)
  • possibly alphabetical trait ordering
  • General grouping, similar to class structure - e.g. transients in the beginning, followed by associations, followed by attributes, followed by traits and factories

Those could be separate cops of course

@Darhazer Darhazer changed the title Cop idea: forceordering in factories Cop idea: force ordering in factories Sep 23, 2022
@pirj
Copy link
Member

pirj commented Oct 15, 2022

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, ...) }.

@ydah ydah transferred this issue from rubocop/rubocop-rspec May 6, 2023
@ydah ydah added the cop label May 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants