diff --git a/CHANGELOG.md b/CHANGELOG.md index 96ef0b292..7240eb989 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## Master (Unreleased) * Fix false positive in `RSpec/Pending` cop when pending is used as a method name. ([@Darhazer][]) +* Fix `FactoryBot/DynamicAttributeDefinedStatically` false positive when using symbol proc argument for a sequence. ([@tdeo][]) ## 1.25.0 (2018-04-07) @@ -330,3 +331,4 @@ Compatibility release so users can upgrade RuboCop to 0.51.0. No new features. [@jojos003]: https://github.com/jojos003 [@abrom]: https://github.com/abrom [@patrickomatic]: https://github.com/patrickomatic +[@tdeo]: https://github.com/tdeo diff --git a/lib/rubocop/cop/rspec/factory_bot/dynamic_attribute_defined_statically.rb b/lib/rubocop/cop/rspec/factory_bot/dynamic_attribute_defined_statically.rb index 18be3847e..629a6cc5c 100644 --- a/lib/rubocop/cop/rspec/factory_bot/dynamic_attribute_defined_statically.rb +++ b/lib/rubocop/cop/rspec/factory_bot/dynamic_attribute_defined_statically.rb @@ -31,13 +31,13 @@ class DynamicAttributeDefinedStatically < Cop (block (send nil? {:factory :trait} ...) _ { (begin $...) $(send ...) } ) PATTERN - def_node_matcher :callback_with_symbol_proc?, <<-PATTERN - (send nil? {:before :after} sym (block_pass sym)) + def_node_matcher :callback_or_sequence_with_symbol_proc?, <<-PATTERN + (send nil? {:before :after :sequence} sym (block_pass sym)) PATTERN def on_block(node) factory_attributes(node).to_a.flatten.each do |attribute| - next if callback_with_symbol_proc?(attribute) || + next if callback_or_sequence_with_symbol_proc?(attribute) || static?(attribute) add_offense(attribute, location: :expression) end diff --git a/spec/rubocop/cop/rspec/factory_bot/dynamic_attribute_defined_statically_spec.rb b/spec/rubocop/cop/rspec/factory_bot/dynamic_attribute_defined_statically_spec.rb index 7ab972bce..66394e6dd 100644 --- a/spec/rubocop/cop/rspec/factory_bot/dynamic_attribute_defined_statically_spec.rb +++ b/spec/rubocop/cop/rspec/factory_bot/dynamic_attribute_defined_statically_spec.rb @@ -87,6 +87,16 @@ RUBY end + it 'accepts valid sequence definition' do + expect_no_offenses(<<-RUBY) + #{factory_bot}.define do + factory :post do + sequence :negative_numbers, &:-@ + end + end + RUBY + end + bad = <<-RUBY #{factory_bot}.define do factory :post do