lib/rubocop/cop/rspec/instance_variable.rb in rubocop-rspec-1.40.0 vs lib/rubocop/cop/rspec/instance_variable.rb in rubocop-rspec-1.41.0
- old
+ new
@@ -45,17 +45,15 @@
# let(:foo) { [] }
# it { expect(foo).to be_empty }
# end
#
class InstanceVariable < Cop
+ include RuboCop::RSpec::TopLevelGroup
+
MSG = 'Avoid instance variables – use let, ' \
'a method call, or a local variable (if possible).'
- EXAMPLE_GROUP_METHODS = ExampleGroups::ALL + SharedGroups::ALL
-
- def_node_matcher :spec_group?, EXAMPLE_GROUP_METHODS.block_pattern
-
def_node_matcher :dynamic_class?, <<-PATTERN
(block (send (const nil? :Class) :new ...) ...)
PATTERN
def_node_matcher :custom_matcher?, <<-PATTERN
@@ -67,12 +65,10 @@
def_node_search :ivar_usage, '$(ivar $_)'
def_node_search :ivar_assigned?, '(ivasgn % ...)'
- def on_block(node)
- return unless spec_group?(node)
-
+ def on_top_level_group(node)
ivar_usage(node) do |ivar, name|
next if valid_usage?(ivar)
next if assignment_only? && !ivar_assigned?(node, name)
add_offense(ivar)