lib/rubocop/cop/rspec/multiple_expectations.rb in rubocop-rspec-1.42.0 vs lib/rubocop/cop/rspec/multiple_expectations.rb in rubocop-rspec-1.43.0
- old
+ new
@@ -43,29 +43,25 @@
# expect(user.name).to eq("John")
# expect(user.age).to eq(22)
# end
# end
#
- class MultipleExpectations < Cop
+ class MultipleExpectations < Base
include ConfigurableMax
MSG = 'Example has too many expectations [%<total>d/%<max>d].'
+ ANYTHING = ->(_node) { true }
+ TRUE = ->(node) { node.true_type? }
+
def_node_matcher :aggregate_failures?, <<-PATTERN
(block {
(send _ _ <(sym :aggregate_failures) ...>)
- (send _ _ ... (hash <(pair (sym :aggregate_failures) true) ...>))
+ (send _ _ ... (hash <(pair (sym :aggregate_failures) %1) ...>))
} ...)
PATTERN
- def_node_matcher :aggregate_failures_present?, <<-PATTERN
- (block {
- (send _ _ <(sym :aggregate_failures) ...>)
- (send _ _ ... (hash <(pair (sym :aggregate_failures) _) ...>))
- } ...)
- PATTERN
-
def_node_matcher :expect?, Expectations::ALL.send_pattern
def_node_matcher :aggregate_failures_block?, <<-PATTERN
(block (send nil? :aggregate_failures ...) ...)
PATTERN
@@ -87,15 +83,15 @@
def example_with_aggregate_failures?(example_node)
node_with_aggregate_failures = find_aggregate_failures(example_node)
return false unless node_with_aggregate_failures
- aggregate_failures?(node_with_aggregate_failures)
+ aggregate_failures?(node_with_aggregate_failures, TRUE)
end
def find_aggregate_failures(example_node)
example_node.send_node.each_ancestor(:block)
- .find { |block_node| aggregate_failures_present?(block_node) }
+ .find { |block_node| aggregate_failures?(block_node, ANYTHING) }
end
def find_expectation(node, &block)
yield if expect?(node) || aggregate_failures_block?(node)