lib/rubocop/cop/rspec/multiple_expectations.rb in rubocop-rspec-1.35.0 vs lib/rubocop/cop/rspec/multiple_expectations.rb in rubocop-rspec-1.36.0
- old
+ new
@@ -48,18 +48,27 @@
class MultipleExpectations < Cop
include ConfigurableMax
MSG = 'Example has too many expectations [%<total>d/%<max>d].'
- def_node_search :with_aggregate_failures?, '(sym :aggregate_failures)'
- def_node_search :disabled_aggregate_failures?, <<-PATTERN
- (pair (sym :aggregate_failures) (false))
+ def_node_matcher :aggregate_failures?, <<-PATTERN
+ (block {
+ (send _ _ <(sym :aggregate_failures) ...>)
+ (send _ _ ... (hash <(pair (sym :aggregate_failures) true) ...>))
+ } ...)
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 _ :aggregate_failures ...) ...)
+ (block (send nil? :aggregate_failures ...) ...)
PATTERN
def on_block(node)
return unless example?(node)
@@ -84,26 +93,9 @@
end
def find_aggregate_failures(example_node)
example_node.send_node.each_ancestor(:block)
.find { |block_node| aggregate_failures_present?(block_node) }
- end
-
- def aggregate_failures_present?(node)
- metadata(node)&.any?(&method(:with_aggregate_failures?))
- end
-
- def aggregate_failures?(example_or_group_node)
- metadata(example_or_group_node)&.any? do |metadata|
- with_aggregate_failures?(metadata) &&
- !disabled_aggregate_failures?(metadata)
- end
- end
-
- def metadata(example_or_group_node)
- RuboCop::RSpec::Example
- .new(example_or_group_node)
- .metadata
end
def find_expectation(node, &block)
yield if expect?(node) || aggregate_failures_block?(node)