diff --git a/lib/rubocop/cop/rspec/factory_bot/attribute_defined_statically.rb b/lib/rubocop/cop/rspec/factory_bot/attribute_defined_statically.rb index 863eb401f..b081d0ff7 100644 --- a/lib/rubocop/cop/rspec/factory_bot/attribute_defined_statically.rb +++ b/lib/rubocop/cop/rspec/factory_bot/attribute_defined_statically.rb @@ -31,12 +31,15 @@ class AttributeDefinedStatically < Cop (send _ !#reserved_method? $...) PATTERN - def_node_search :factory_attributes, <<-PATTERN + def_node_matcher :factory_attributes, <<-PATTERN (block (send _ #attribute_defining_method? ...) _ { (begin $...) $(send ...) } ) PATTERN def on_block(node) - factory_attributes(node).to_a.flatten.each do |attribute| + attributes = factory_attributes(node) || [] + attributes = [attributes] unless attributes.is_a?(Array) + + attributes.each do |attribute| next unless offensive_receiver?(attribute.receiver, node) next if proc?(attribute) || association?(attribute.first_argument)