Skip to content

Commit 57ea818

Browse files
authored
Merge pull request #1285 from tejasbubane/fix-1284
Fix error in `RSpec/RSpec/FactoryBot/CreateList` cop for empty block
2 parents 17aca30 + d8b747b commit 57ea818

File tree

3 files changed

+8
-0
lines changed

3 files changed

+8
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* Fix autocorrect for EmptyLineSeparation. ([@johnny-miyake][])
77
* Add new `RSpec/Capybara/SpecificMatcher` cop. ([@ydah][])
88
* Fixed false offense detection in `FactoryBot/CreateList` when a n.times block is including method calls in the factory create arguments. ([@ngouy][])
9+
* Fix error in `RSpec/RSpec/FactoryBot/CreateList` cop for empty block. ([@tejasbubane][])
910

1011
## 2.11.1 (2022-05-18)
1112

lib/rubocop/cop/rspec/factory_bot/create_list.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ def on_block(node)
7676

7777
return unless n_times_block?(node)
7878
return if n_times_block_with_arg_and_used?(node)
79+
return unless node.body
7980
return if arguments_include_method_call?(node.body)
8081
return unless contains_only_factory?(node.body)
8182

spec/rubocop/cop/rspec/factory_bot/create_list_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,12 @@
8282
RUBY
8383
end
8484

85+
it 'ignores empty n.times' do
86+
expect_no_offenses(<<~RUBY)
87+
3.times {}
88+
RUBY
89+
end
90+
8591
it 'ignores n.times when there is other calls but create' do
8692
expect_no_offenses(<<~RUBY)
8793
used_passwords = []

0 commit comments

Comments
 (0)