diff --git a/Gemfile b/Gemfile index 515dec7c8..c70327b19 100644 --- a/Gemfile +++ b/Gemfile @@ -4,6 +4,8 @@ source 'https://rubygems.org' gemspec +gem 'rubocop-ast', github: 'marcandre/rubocop-ast', branch: 'nodepatternmatch' + local_gemfile = 'Gemfile.local' if File.exist?(local_gemfile) diff --git a/lib/rubocop/cop/rspec/multiple_expectations.rb b/lib/rubocop/cop/rspec/multiple_expectations.rb index 2910d5213..184ddcafd 100644 --- a/lib/rubocop/cop/rspec/multiple_expectations.rb +++ b/lib/rubocop/cop/rspec/multiple_expectations.rb @@ -50,17 +50,12 @@ class MultipleExpectations < Cop MSG = 'Example has too many expectations [%d/%d].' - def_node_matcher :aggregate_failures?, <<-PATTERN - (block { - (send _ _ <(sym :aggregate_failures) ...>) - (send _ _ ... (hash <(pair (sym :aggregate_failures) true) ...>)) - } ...) - PATTERN + ANYTHING = ->(_) { true } - def_node_matcher :aggregate_failures_present?, <<-PATTERN + def_node_matcher :aggregate_failures?, <<-PATTERN (block { (send _ _ <(sym :aggregate_failures) ...>) - (send _ _ ... (hash <(pair (sym :aggregate_failures) _) ...>)) + (send _ _ ... (hash <(pair (sym :aggregate_failures) %1) ...>)) } ...) PATTERN @@ -89,12 +84,12 @@ 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_type?.to_proc) 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) diff --git a/rubocop-rspec.gemspec b/rubocop-rspec.gemspec index 48af29b11..65c2346e0 100644 --- a/rubocop-rspec.gemspec +++ b/rubocop-rspec.gemspec @@ -37,6 +37,7 @@ Gem::Specification.new do |spec| } spec.add_runtime_dependency 'rubocop', '>= 0.68.1' + spec.add_runtime_dependency 'rubocop-ast' spec.add_development_dependency 'rack' spec.add_development_dependency 'rake'