lib/rubocop/cop/rspec/described_class.rb in rubocop-rspec-2.12.1 vs lib/rubocop/cop/rspec/described_class.rb in rubocop-rspec-2.13.0
- old
+ new
@@ -55,10 +55,11 @@
# end
#
class DescribedClass < Base
extend AutoCorrector
include ConfigurableEnforcedStyle
+ include Namespace
DESCRIBED_CLASS = 'described_class'
MSG = 'Use `%<replacement>s` instead of `%<src>s`.'
# @!method common_instance_exec_closure?(node)
@@ -79,11 +80,11 @@
# @!method contains_described_class?(node)
def_node_search :contains_described_class?,
'(send nil? :described_class)'
- def on_block(node)
+ def on_block(node) # rubocop:disable InternalAffairs/NumblockHandler
# In case the explicit style is used, we need to remember what's
# being described.
@described_class, body = described_constant(node)
return unless body
@@ -158,11 +159,12 @@
full_const_name(nearest_described_class) == full_const_name(node)
end
def full_const_name(node)
- collapse_namespace(namespace(node), const_name(node))
+ symbolized_namespace = namespace(node).map(&:to_sym)
+ collapse_namespace(symbolized_namespace, const_name(node))
end
# @param namespace [Array<Symbol>]
# @param const [Array<Symbol>]
# @return [Array<Symbol>]
@@ -197,21 +199,9 @@
elsif namespace.const_type?
[*const_name(namespace), name]
elsif %i[lvar cbase send].include?(namespace.type)
[nil, name]
end
- end
-
- # @param node [RuboCop::AST::Node]
- # @return [Array<Symbol>]
- # @example
- # namespace(node) # => [:A, :B, :C]
- def namespace(node)
- node
- .each_ancestor(:class, :module)
- .reverse_each
- .flat_map { |ancestor| ancestor.defined_module_name.split('::') }
- .map(&:to_sym)
end
end
end
end
end