Skip to content

Instantly share code, notes, and snippets.

@meg-gutshall
Created August 11, 2023 17:18
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 meg-gutshall/0a5b34bd1540de6ff69541ef3fe03403 to your computer and use it in GitHub Desktop.
Save meg-gutshall/0a5b34bd1540de6ff69541ef3fe03403 to your computer and use it in GitHub Desktop.
Colorized FactoryBot Linter
# frozen_string_literal: true
require 'colorize'
require 'English'
namespace :factory_bot do
desc 'Verify that all FactoryBot factories are valid'
task lint: :environment do
return unless Rails.env.development?
FactoryBot.lint factories_to_lint, traits: true
fail ActiveRecord::Rollback
end
end
def factories_to_lint
FactoryBot.factories.reject do |factory|
factory.name =~ /^old_/
end
end
module FactoryBot
class Linter
class FactoryError
def message
message = @wrapped_error.message
'* '.colorize(:light_red) +
location.to_s.colorize(:light_yellow) +
' - '.colorize(:light_red) +
message.to_s.colorize(:light_blue) +
" (#{@wrapped_error.class.name})".colorize(:light_red)
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment