Module: RuboCop::Cop::Capybara::CapybaraHelp Private
- Defined in:
- lib/rubocop/cop/capybara/mixin/capybara_help.rb
Overview
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
Help methods for capybara.
Constant Summary collapse
- COMMON_OPTIONS =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
%w[ id class style ].freeze
- SPECIFIC_OPTIONS =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
{ 'button' => ( COMMON_OPTIONS + %w[disabled name value title type] ).freeze, 'link' => ( COMMON_OPTIONS + %w[href alt title download] ).freeze, 'table' => ( COMMON_OPTIONS + %w[cols rows] ).freeze, 'select' => ( COMMON_OPTIONS + %w[ disabled name placeholder selected multiple ] ).freeze, 'field' => ( COMMON_OPTIONS + %w[ checked disabled name placeholder readonly type multiple ] ).freeze }.freeze
- SPECIFIC_PSEUDO_CLASSES =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
%w[ not() disabled enabled checked unchecked ].freeze
Class Method Summary collapse
- .common_attributes?(selector) ⇒ Boolean private
- .include_option?(node, option) ⇒ Boolean private
- .replaceable_attributes?(attrs) ⇒ Boolean private
- .replaceable_element?(node, element, attrs) ⇒ Boolean private
- .replaceable_option?(node, locator, element) ⇒ Boolean private
- .replaceable_pseudo_class?(pseudo_class, locator) ⇒ Boolean private
- .replaceable_pseudo_class_not?(locator) ⇒ Boolean private
- .replaceable_pseudo_classes?(locator) ⇒ Boolean private
- .replaceable_to_link?(node, attrs) ⇒ Boolean private
Class Method Details
.common_attributes?(selector) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
61 62 63 |
# File 'lib/rubocop/cop/capybara/mixin/capybara_help.rb', line 61 def common_attributes?(selector) CssSelector.attributes(selector).keys.difference(COMMON_OPTIONS).none? end |
.include_option?(node, option) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
125 126 127 |
# File 'lib/rubocop/cop/capybara/mixin/capybara_help.rb', line 125 def include_option?(node, option) node.each_descendant(:sym).find { |opt| opt.value == option } end |
.replaceable_attributes?(attrs) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
70 71 72 |
# File 'lib/rubocop/cop/capybara/mixin/capybara_help.rb', line 70 def replaceable_attributes?(attrs) attrs.values.none?(&:nil?) end |
.replaceable_element?(node, element, attrs) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
108 109 110 111 112 113 |
# File 'lib/rubocop/cop/capybara/mixin/capybara_help.rb', line 108 def replaceable_element?(node, element, attrs) case element when 'link' then replaceable_to_link?(node, attrs) else true end end |
.replaceable_option?(node, locator, element) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
45 46 47 48 49 50 51 52 |
# File 'lib/rubocop/cop/capybara/mixin/capybara_help.rb', line 45 def replaceable_option?(node, locator, element) attrs = CssSelector.attributes(locator).keys return false unless replaceable_element?(node, element, attrs) attrs.all? do |attr| SPECIFIC_OPTIONS.fetch(element, []).include?(attr) end end |
.replaceable_pseudo_class?(pseudo_class, locator) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
85 86 87 88 89 90 91 92 |
# File 'lib/rubocop/cop/capybara/mixin/capybara_help.rb', line 85 def replaceable_pseudo_class?(pseudo_class, locator) return false unless SPECIFIC_PSEUDO_CLASSES.include?(pseudo_class) case pseudo_class when 'not()' then replaceable_pseudo_class_not?(locator) else true end end |
.replaceable_pseudo_class_not?(locator) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
96 97 98 99 100 101 102 |
# File 'lib/rubocop/cop/capybara/mixin/capybara_help.rb', line 96 def replaceable_pseudo_class_not?(locator) locator.scan(/not\(.*?\)/).all? do |negation| CssSelector.attributes(negation).values.all? do |v| v.is_a?(TrueClass) || v.is_a?(FalseClass) end end end |
.replaceable_pseudo_classes?(locator) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
76 77 78 79 80 |
# File 'lib/rubocop/cop/capybara/mixin/capybara_help.rb', line 76 def replaceable_pseudo_classes?(locator) CssSelector.pseudo_classes(locator).all? do |pseudo_class| replaceable_pseudo_class?(pseudo_class, locator) end end |
.replaceable_to_link?(node, attrs) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
118 119 120 |
# File 'lib/rubocop/cop/capybara/mixin/capybara_help.rb', line 118 def replaceable_to_link?(node, attrs) include_option?(node, :href) || attrs.include?('href') end |