lib/rubocop/cop/capybara/specific_actions.rb in rubocop-capybara-2.17.0 vs lib/rubocop/cop/capybara/specific_actions.rb in rubocop-capybara-2.17.1
- old
+ new
@@ -39,22 +39,32 @@
# separated by whitespace.
# because the `.click` is executed on the element to
# which the last selector points.
next unless (selector = last_selector(arg))
next unless (action = specific_action(selector))
- next unless CapybaraHelp.specific_option?(node.receiver, arg,
- action)
- next unless CapybaraHelp.specific_pseudo_classes?(arg)
+ next unless replaceable?(node, arg, action)
range = offense_range(node, node.receiver)
add_offense(range, message: message(action, selector))
end
end
private
def specific_action(selector)
SPECIFIC_ACTION[last_selector(selector)]
+ end
+
+ def replaceable?(node, arg, action)
+ replaceable_attributes?(arg) &&
+ CapybaraHelp.replaceable_option?(node.receiver, arg, action) &&
+ CapybaraHelp.replaceable_pseudo_classes?(arg)
+ end
+
+ def replaceable_attributes?(selector)
+ CapybaraHelp.replaceable_attributes?(
+ CssSelector.attributes(selector)
+ )
end
def supported_selector?(selector)
!selector.match?(/[>,+~]/)
end