DRY in builders

This commit is contained in:
Thomas Walpole 2018-10-16 11:58:39 -07:00
parent 8648cbf75b
commit f72cca9543
2 changed files with 3 additions and 6 deletions

View File

@ -35,8 +35,7 @@ module Capybara
when XPath::Expression
raise ArgumentError, 'XPath expressions are not supported for the :class filter with CSS based selectors'
when Regexp
strs = Selector::RegexpDisassembler.new(classes).substrings
strs.map { |str| "[class*='#{str}'#{' i' if classes.casefold?}]" }.join
attribute_conditions(class: classes)
else
cls = Array(classes).group_by { |cl| cl.start_with? '!' }
(cls[false].to_a.map { |cl| ".#{Capybara::Selector::CSS.escape(cl)}" } +

View File

@ -26,10 +26,8 @@ module Capybara
def class_conditions(classes)
case classes
when XPath::Expression
XPath.attr(:class)[classes]
when Regexp
XPath.attr(:class)[regexp_to_xpath_conditions(classes)]
when XPath::Expression, Regexp
attribute_conditions(class: classes)
else
Array(classes).map do |klass|
if klass.start_with?('!')