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: FactoryBot trait usage style in nested factories #8

Open
pirj opened this issue Oct 23, 2022 · 0 comments
Open

Cop idea: FactoryBot trait usage style in nested factories #8

pirj opened this issue Oct 23, 2022 · 0 comments
Labels

Comments

@pirj
Copy link
Member

pirj commented Oct 23, 2022

Traits can be used in nested factories in two different ways.

Explicitly (and unambiguously):

factory :word do
  letters { "bar" }
  type { "noun" }

  trait :article do
    type { :article }
  end

  factory :the, traits: [:article] do
    letters { "the" }
  end

Another way, as implicit attributes is ambiguous:

factory :word do
  letters { "bar" }
  type { "noun" }

  trait :article do
    type { :article }
  end

  factory :the do
    article # association or a trait?
    letters { "the" }
  end

Unless we parse traits in context, it's hard to understand if article is an association or a trait.
With factory :verb, parent: :word placed in a separate file, this is getting impossible.

@pirj pirj changed the title FactoryBot traits style FactoryBot trait usage style in nested factories Oct 23, 2022
@pirj pirj changed the title FactoryBot trait usage style in nested factories Cop idea: FactoryBot trait usage style in nested factories Oct 23, 2022
@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

2 participants