Skip to content
Snippets Groups Projects
Unverified Commit cf98bd6c authored by Mike McQuaid's avatar Mike McQuaid Committed by GitHub
Browse files

Merge pull request #6846 from Homebrew/dependabot/bundler/Library/Homebrew/rubocop-rspec-1.37.1

build: bump rubocop-rspec from 1.37.0 to 1.37.1 in /Library/Homebrew
parents 4973f670 4a7a16e3
No related branches found
No related tags found
No related merge requests found
Showing
with 16 additions and 1 deletion
......@@ -6,6 +6,11 @@ module RuboCop
module FactoryBot
# Use string value when setting the class attribute explicitly.
#
# This cop would promote faster tests by lazy-loading of
# application files. Also, this could help you suppress potential bugs
# in combination with external libraries by avoiding a preload of
# application files from the factory files.
#
# @example
# # bad
# factory :foo, class: Foo do
......@@ -15,7 +20,9 @@ module RuboCop
# factory :foo, class: 'Foo' do
# end
class FactoryClassName < Cop
MSG = "Pass '%<class_name>s' instead of %<class_name>s."
MSG = "Pass '%<class_name>s' string instead of `%<class_name>s` " \
'constant.'
ALLOWED_CONSTANTS = %w[Hash OpenStruct].freeze
def_node_matcher :class_name, <<~PATTERN
(send _ :factory _ (hash <(pair (sym :class) $(const ...)) ...>))
......@@ -23,6 +30,8 @@ module RuboCop
def on_send(node)
class_name(node) do |cn|
next if allowed?(cn.const_name)
add_offense(cn, message: format(MSG, class_name: cn.const_name))
end
end
......@@ -32,6 +41,12 @@ module RuboCop
corrector.replace(node.loc.expression, "'#{node.source}'")
end
end
private
def allowed?(const_name)
ALLOWED_CONSTANTS.include?(const_name)
end
end
end
end
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment