Skip to content

Conversation

@pablobm
Copy link
Contributor

@pablobm pablobm commented Dec 10, 2025

I noticed that some factory files were named in the singular and some in the plural. This PR makes it all consistent by using the singular for all.

I don't think there's a clear convention one whether to use either. To me, it makes sense to use the singular as the factories themselves are in the singular: create(:user).

@gravitystorm
Copy link
Collaborator

I agree this should be consistent.

It's exactly the kind of thing we need a linter for, otherwise it'll just drift again in the future - it's clearly not an easy thing to spot during reviews! I've checked the rubocop-factory_bot repo, and found rubocop/rubocop-factory_bot#57 . Ideally, that would be implemented upstream, or perhaps we would implement it ourselves as a custom cop.

As for which name - it seems like there's three conventions:

  • singular model name
  • plural model name
  • singular model name plus "_factory" suffix

I've check the factory_bot docs, and they don't mention anything. annotate_models (mentioned in the issue above) supports the three alternatives (while referring to "_factory" suffix as "old style"). Neither Discourse nor Mastodon use factory_bot. I can't find a style guide with any suggestions.

Personally I prefer the plural option, since my IDE then shows "user.rb" and "users.rb" and I know which is which 😄 But I'm eager to find some better reasoning than that.

@pablobm
Copy link
Contributor Author

pablobm commented Dec 11, 2025

From those options, I prefer <singular>_factory.rb, because:

  • The factory within is defined in the singular. It feels weird to me that factories/users.rb defines internally a factory :user.
  • The suffix helps telling the file from others in an IDE (in a list of tabs or similar).

But I have worked in projects with the plural before and I can live with it. In fact I think plural might be more widespread...

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.

2 participants