Class: RuboCop::Cop::Workit::RSpecCapybaraPredicateMatcher
- Inherits:
-
Base
- Object
- Base
- RuboCop::Cop::Workit::RSpecCapybaraPredicateMatcher
- Extended by:
- AutoCorrector
- Includes:
- RSpecPredicateMatcherBase
- Defined in:
- lib/rubocop/cop/workit/rspec_capybara_predicate_matcher.rb
Overview
Prefer using predicate matcher over using predicate method directly.
Capybara defines magic matchers for predicate methods. This cop recommends to use the predicate matcher instead of using predicate method directly.
Constant Summary collapse
- MATCHER_SUFFIX =
%w[css selector style xpath].freeze
- INFLECTED_MATCHER =
MATCHER_SUFFIX.each.map do |suffix| "match_#{suffix}" end.freeze
- EXPLICIT_MATCHER =
MATCHER_SUFFIX.each.map do |suffix| "matches_#{suffix}?" end.freeze
Constants included from RSpecPredicateMatcherBase
RuboCop::Cop::Workit::RSpecPredicateMatcherBase::RESTRICT_ON_SEND
Constants included from RSpecExplicitHelp
RuboCop::Cop::Workit::RSpecExplicitHelp::BUILT_IN_MATCHERS, RuboCop::Cop::Workit::RSpecExplicitHelp::MSG_EXPLICIT
Constants included from RSpecInflectedHelp
RuboCop::Cop::Workit::RSpecInflectedHelp::MSG_INFLECTED
Instance Method Summary collapse
- #predicate?(sym) ⇒ Boolean
- #predicate_matcher_name?(name) ⇒ Boolean
- #to_predicate_matcher(name) ⇒ Object
- #to_predicate_method(matcher) ⇒ Object
Methods included from RSpecPredicateMatcherBase
Instance Method Details
#predicate?(sym) ⇒ Boolean
73 74 75 |
# File 'lib/rubocop/cop/workit/rspec_capybara_predicate_matcher.rb', line 73 def predicate?(sym) EXPLICIT_MATCHER.include?(sym.to_s) end |
#predicate_matcher_name?(name) ⇒ Boolean
62 63 64 65 66 67 |
# File 'lib/rubocop/cop/workit/rspec_capybara_predicate_matcher.rb', line 62 def predicate_matcher_name?(name) name = name.to_s return false if allowed_explicit_matchers.include?(name) INFLECTED_MATCHER.include?(name) end |
#to_predicate_matcher(name) ⇒ Object
69 70 71 |
# File 'lib/rubocop/cop/workit/rspec_capybara_predicate_matcher.rb', line 69 def to_predicate_matcher(name) name.to_s.sub("matches_", "match_")[0..-2] end |
#to_predicate_method(matcher) ⇒ Object
77 78 79 |
# File 'lib/rubocop/cop/workit/rspec_capybara_predicate_matcher.rb', line 77 def to_predicate_method(matcher) "#{matcher.to_s.sub("match_", "matches_")}?" end |