Skip to content

Instantly share code, notes, and snippets.

@kei-s
Last active July 1, 2022 02:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kei-s/7d5d9d653e3784c6652b6324af27add7 to your computer and use it in GitHub Desktop.
Save kei-s/7d5d9d653e3784c6652b6324af27add7 to your computer and use it in GitHub Desktop.
Check unused FactoryBot definitions
# brew install prce2
# RAILS_ENV=test bin/rails r check_unused_factory_bot.rb
FactoryBot.factories.each do |factory|
command = %!pcregrep -Mr "(build|build_list|create|create_list)\\(\\n? *:#{factory.name}(,|\\))" spec!
result = `#{command}`
puts factory.name if result.chomp.empty?
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment