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

Remove guideline about using one factories.rb file per project #685

Merged

Conversation

sarahraqueld
Copy link
Contributor

@sarahraqueld sarahraqueld commented Jun 29, 2023

From my experience working with projects using FactoryBot, this guideline is not something we follow. When asking the opinion of others at thoughtbot, they agreed they prefer to split up factories into their own individual files as this makes it easier to navigate and find them, as opposed to having to look for factories in a big file.

This guideline was first introduced 11 years ago (commit) and we have learned a lot since then.

What are your thoughts?

@sarahraqueld sarahraqueld force-pushed the remove-guide-about-one-big-factory-file-per-project branch from 6adef16 to 464e479 Compare June 29, 2023 13:46
@nickcharlton
Copy link
Member

I feel like my opinion on this changes once it gets to a certain size. When it's easy to skim up and down, one file is really helpful. But once it gets over a certain size, it's more difficult to get a feeling of the factories when scanning it. The prior rule of keeping them alphabetically sorted helps this a lot, but is not, in my experience, followed.

How do people feel that we should split the file? By model? Or something else?

@thoughtbot-summer
Copy link
Member

But once it gets over a certain size

I think that this is inevitable for most projects. I guess if you know your project will remain very small, keeping all of the factories in one file could make things more readable, but I've encountered very few projects like that.

How do people feel that we should split the file? By model? Or something else?

I think generally one factory per file is good.

Copy link
Contributor

@MatheusRich MatheusRich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like one file / factory. The only annoying thing one searching for files in my editor (CMD + P), they always show up along side models. I wonder if they were called spec/factories/<model>_factory.rb. (with the _factory suffix) would help.

Copy link
Contributor

@mike-burns mike-burns left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I approve of deleting guidelines in general, so LGTM.

Copy link
Member

@neilvcarvalho neilvcarvalho left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also prefer splitting factories.rb when it reaches a certain size. As each project will have its own needs, I like the idea of not specifying anything on the guides.

Copy link

@rdnewmanbot rdnewmanbot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with this change

@sarahraqueld sarahraqueld merged commit df8efa1 into main Jul 10, 2023
@sarahraqueld sarahraqueld deleted the remove-guide-about-one-big-factory-file-per-project branch July 10, 2023 13:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants