Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b3507f7

Browse files
author
Maxim Krizhanovsky
authored
Merge pull request rubocop#707 from rubocop-hq/fix-create-list-cop
Fix rubocop#702: don't flag n.times block with an argument
2 parents b211df9 + aafd02f commit b3507f7

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## Master (Unreleased)
44

5+
* `FactoryBot/CreateList` now ignores `times` blocks with an argument. ([@Darhazer][])
6+
57
## 1.30.0 (2018-10-08)
68

79
* Add config to `RSpec/VerifiedDoubles` to enforcement of verification on unnamed doubles. ([@BrentWheeldon][])

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

+3-2
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,10 @@ class CreateList < Cop
3030
MSG_CREATE_LIST = 'Prefer create_list.'.freeze
3131
MSG_N_TIMES = 'Prefer %<number>s.times.'.freeze
3232

33-
def_node_matcher :n_times_block?, <<-PATTERN
33+
def_node_matcher :n_times_block_without_arg?, <<-PATTERN
3434
(block
3535
(send (int _) :times)
36+
(args)
3637
...
3738
)
3839
PATTERN
@@ -47,7 +48,7 @@ class CreateList < Cop
4748

4849
def on_block(node)
4950
return unless style == :create_list
50-
return unless n_times_block?(node)
51+
return unless n_times_block_without_arg?(node)
5152
return unless contains_only_factory?(node.body)
5253

5354
add_offense(node.send_node,

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

+2-3
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,9 @@
4141
RUBY
4242
end
4343

44-
it 'flags n.times with argument' do
45-
expect_offense(<<-RUBY)
44+
it 'ignores n.times with argument' do
45+
expect_no_offenses(<<-RUBY)
4646
3.times { |n| create :user, created_at: n.days.ago }
47-
^^^^^^^ Prefer create_list.
4847
RUBY
4948
end
5049

0 commit comments

Comments
 (0)