lib/rubocop/cop/rspec/iterated_expectation.rb in rubocop-rspec-2.12.1 vs lib/rubocop/cop/rspec/iterated_expectation.rb in rubocop-rspec-2.13.0

- old
+ new

@@ -13,10 +13,11 @@ # # # good # it 'validates users' do # expect([user1, user2, user3]).to all(be_valid) # end + # class IteratedExpectation < Base MSG = 'Prefer using the `all` matcher instead ' \ 'of iterating over an array.' # @!method each?(node) @@ -26,17 +27,32 @@ (args (arg $_)) $(...) ) PATTERN + # @!method each_numblock?(node) + def_node_matcher :each_numblock?, <<-PATTERN + (numblock + (send ... :each) _ $(...) + ) + PATTERN + # @!method expectation?(node) def_node_matcher :expectation?, <<-PATTERN (send (send nil? :expect (lvar %)) :to ...) PATTERN def on_block(node) each?(node) do |arg, body| if single_expectation?(body, arg) || only_expectations?(body, arg) + add_offense(node.send_node) + end + end + end + + def on_numblock(node) + each_numblock?(node) do |body| + if single_expectation?(body, :_1) || only_expectations?(body, :_1) add_offense(node.send_node) end end end