Skip to content

Commit 3b41df3

Browse files
committed
Use node pattern generic parameters to simplify cop
#804 (comment) Support introduced in rubocop/rubocop-ast#31 Presumably this will land in RuboCop 1.0 or 1.0.1 worst case.
1 parent 5d4a1be commit 3b41df3

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

lib/rubocop/cop/rspec/multiple_expectations.rb

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,13 @@ class MultipleExpectations < Cop
5050

5151
MSG = 'Example has too many expectations [%<total>d/%<max>d].'
5252

53-
def_node_matcher :aggregate_failures?, <<-PATTERN
54-
(block {
55-
(send _ _ <(sym :aggregate_failures) ...>)
56-
(send _ _ ... (hash <(pair (sym :aggregate_failures) true) ...>))
57-
} ...)
58-
PATTERN
53+
ANYTHING = ->(_node) { true }
54+
TRUE = ->(node) { node.true_type? }
5955

60-
def_node_matcher :aggregate_failures_present?, <<-PATTERN
56+
def_node_matcher :aggregate_failures?, <<-PATTERN
6157
(block {
6258
(send _ _ <(sym :aggregate_failures) ...>)
63-
(send _ _ ... (hash <(pair (sym :aggregate_failures) _) ...>))
59+
(send _ _ ... (hash <(pair (sym :aggregate_failures) %1) ...>))
6460
} ...)
6561
PATTERN
6662

@@ -89,12 +85,12 @@ def example_with_aggregate_failures?(example_node)
8985
node_with_aggregate_failures = find_aggregate_failures(example_node)
9086
return false unless node_with_aggregate_failures
9187

92-
aggregate_failures?(node_with_aggregate_failures)
88+
aggregate_failures?(node_with_aggregate_failures, TRUE)
9389
end
9490

9591
def find_aggregate_failures(example_node)
9692
example_node.send_node.each_ancestor(:block)
97-
.find { |block_node| aggregate_failures_present?(block_node) }
93+
.find { |block_node| aggregate_failures?(block_node, ANYTHING) }
9894
end
9995

10096
def find_expectation(node, &block)

0 commit comments

Comments
 (0)