Class: Nucop::ShadowingFactoryBotCreationMethods

Inherits:
RuboCop::Cop::Cop
  • Object
show all
Includes:
Helpers::FilePathHelper
Defined in:
lib/nucop/cops/shadowing_factory_bot_creation_methods.rb

Overview

This cop looks for defined methods in spec files that would shadow methods defined in FactoryBot::Syntax::Methods. See FactoryBotHelper::FACTORY_BOT_METHODS constant for a complete list.

Examples:


# bad

def create(args)
  ...
end

# good

def create_transfer_pallet(args)
  ...
end

Constant Summary collapse

MSG =
"Method `%<method>s` shadows a FactoryBot method. Please rename it to be more specific."

Instance Method Summary collapse

Methods included from Helpers::FilePathHelper

#acceptance_or_spec_file?, #support_file?

Instance Method Details

#on_def(node) ⇒ Object



27
28
29
30
31
# File 'lib/nucop/cops/shadowing_factory_bot_creation_methods.rb', line 27

def on_def(node)
  factory_bot_methods(node) do |method|
    add_offense(node, location: :expression, message: format(MSG, method: method))
  end
end

#relevant_file?(file) ⇒ Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/nucop/cops/shadowing_factory_bot_creation_methods.rb', line 33

def relevant_file?(file)
  acceptance_or_spec_file?(file) && super
end