lib/rubocop/cop/rspec/instance_variable.rb in rubocop-rspec-1.37.1 vs lib/rubocop/cop/rspec/instance_variable.rb in rubocop-rspec-1.38.0

- old
+ new

@@ -56,28 +56,37 @@ def_node_matcher :dynamic_class?, <<-PATTERN (block (send (const nil? :Class) :new ...) ...) PATTERN + def_node_matcher :custom_matcher?, <<-PATTERN + (block { + (send nil? :matcher sym) + (send (const (const nil? :RSpec) :Matchers) :define sym) + } ...) + PATTERN + def_node_search :ivar_usage, '$(ivar $_)' def_node_search :ivar_assigned?, '(ivasgn % ...)' def on_block(node) return unless spec_group?(node) ivar_usage(node) do |ivar, name| - return if inside_dynamic_class?(ivar) - return if assignment_only? && !ivar_assigned?(node, name) + next if valid_usage?(ivar) + next if assignment_only? && !ivar_assigned?(node, name) add_offense(ivar) end end private - def inside_dynamic_class?(node) - node.each_ancestor(:block).any? { |block| dynamic_class?(block) } + def valid_usage?(node) + node.each_ancestor(:block).any? do |block| + dynamic_class?(block) || custom_matcher?(block) + end end def assignment_only? cop_config['AssignmentOnly'] end