Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Runners in language module #746

Merged
merged 2 commits into from
Mar 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/rubocop/cop/rspec/be.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class Be < Cop
MSG = 'Don\'t use `be` without an argument.'.freeze

def_node_matcher :be_without_args, <<-PATTERN
(send _ {:to :not_to :to_not} $(send nil? :be))
(send _ #{Runners::ALL.node_pattern_union} $(send nil? :be))
PATTERN

def on_send(node)
Expand Down
4 changes: 2 additions & 2 deletions lib/rubocop/cop/rspec/capybara/current_path_expectation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ class CurrentPathExpectation < Cop
# Supported matchers: eq(...) / match(/regexp/) / match('regexp')
def_node_matcher :as_is_matcher, <<-PATTERN
(send
#expectation_set_on_current_path ${:to :not_to :to_not}
#expectation_set_on_current_path $#{Runners::ALL.node_pattern_union}
${(send nil? :eq ...) (send nil? :match (regexp ...))})
PATTERN

def_node_matcher :regexp_str_matcher, <<-PATTERN
(send
#expectation_set_on_current_path ${:to :not_to :to_not}
#expectation_set_on_current_path $#{Runners::ALL.node_pattern_union}
$(send nil? :match (str $_)))
PATTERN

Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/rspec/implicit_expect.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class ImplicitExpect < Cop
def_node_matcher :implicit_expect, <<-PATTERN
{
(send nil? ${:should :should_not} ...)
(send (send nil? $:is_expected) {:to :to_not :not_to} ...)
(send (send nil? $:is_expected) #{Runners::ALL.node_pattern_union} ...)
}
PATTERN

Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/rspec/invalid_predicate_matcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class InvalidPredicateMatcher < Cop
MSG = 'Omit `?` from `%<matcher>s`.'.freeze

def_node_matcher :invalid_predicate_matcher?, <<-PATTERN
(send (send nil? :expect ...) {:to :not_to :to_not} $(send nil? #predicate?))
(send (send nil? :expect ...) #{Runners::ALL.node_pattern_union} $(send nil? #predicate?))
PATTERN

def on_send(node)
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/rspec/message_spies.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class MessageSpies < Cop
SUPPORTED_STYLES = %w[have_received receive].freeze

def_node_matcher :message_expectation, %(
(send (send nil? :expect $_) {:to :to_not :not_to} ...)
(send (send nil? :expect $_) #{Runners::ALL.node_pattern_union} ...)
)

def_node_search :receive_message, %(
Expand Down
8 changes: 5 additions & 3 deletions lib/rubocop/cop/rspec/predicate_matcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module Cop
module RSpec
# A helper for `inflected` style
module InflectedHelper
include RuboCop::RSpec::Language
extend NodePattern::Macros

MSG_INFLECTED = 'Prefer using `%<matcher_name>s` matcher over ' \
Expand All @@ -25,7 +26,7 @@ def check_inflected(node)
(send nil? :expect {
(block $(send !nil? #predicate? ...) ...)
$(send !nil? #predicate? ...)})
${:to :not_to :to_not}
$#{Runners::ALL.node_pattern_union}
$#boolean_matcher?)
PATTERN

Expand Down Expand Up @@ -123,6 +124,7 @@ def true?(to_symbol, matcher)
# A helper for `explicit` style
# rubocop:disable Metrics/ModuleLength
module ExplicitHelper
include RuboCop::RSpec::Language
extend NodePattern::Macros

MSG_EXPLICIT = 'Prefer using `%<predicate_name>s` over ' \
Expand Down Expand Up @@ -160,7 +162,7 @@ def check_explicit(node) # rubocop:disable Metrics/MethodLength
def_node_matcher :predicate_matcher?, <<-PATTERN
(send
(send nil? :expect $!nil?)
{:to :not_to :to_not}
#{Runners::ALL.node_pattern_union}
{$(send nil? #predicate_matcher_name? ...)
(block $(send nil? #predicate_matcher_name? ...) ...)})
PATTERN
Expand All @@ -169,7 +171,7 @@ def check_explicit(node) # rubocop:disable Metrics/MethodLength
(block
(send
(send nil? :expect $!nil?)
{:to :not_to :to_not}
#{Runners::ALL.node_pattern_union}
$(send nil? #predicate_matcher_name?))
...)
PATTERN
Expand Down
7 changes: 6 additions & 1 deletion lib/rubocop/rspec/language.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,19 @@ module Expectations
ALL = SelectorSet.new(%i[expect is_expected expect_any_instance_of])
end

module Runners
ALL = SelectorSet.new(%i[to to_not not_to])
end

ALL =
ExampleGroups::ALL +
SharedGroups::ALL +
Examples::ALL +
Hooks::ALL +
Helpers::ALL +
Subject::ALL +
Expectations::ALL
Expectations::ALL +
Runners::ALL
end
end
end