Skip to content

Fix docs about definition file paths #1626

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

Merged
merged 1 commit into from
Mar 31, 2025

Conversation

r7kamura
Copy link
Contributor

@r7kamura r7kamura commented Feb 20, 2024

The current implementation seems to load all definition files that match the following pattern in this order:

  1. factories.rb
  2. factories/**/*.rb
  3. test/factories.rb
  4. test/factories/**/*.rb
  5. spec/factories.rb
  6. spec/factories/**/*.rb

self.definition_file_paths = %w[factories test/factories spec/factories]
def self.find_definitions
absolute_definition_file_paths = definition_file_paths.map { |path| File.expand_path(path) }
absolute_definition_file_paths.uniq.each do |path|
load("#{path}.rb") if File.exist?("#{path}.rb")
if File.directory? path
Dir[File.join(path, "**", "*.rb")].sort.each do |file|
load file
end
end
end
end

There are several documents that mention definition file paths, but none of them are consistent with the current implementation. So I propose to first eliminate the gap between the documentation and the implementation in this pull request.

I would also be interested to know if this implementation is intentional or not, as it is important to know which files should be ideally scanned by rubocop-factory_bot.

@purinkle purinkle force-pushed the definition-file-paths branch from 9341451 to acc095e Compare March 31, 2025 12:46
@purinkle purinkle merged commit acc095e into thoughtbot:main Mar 31, 2025
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants