DRY in builders
This commit is contained in:
parent
8648cbf75b
commit
f72cca9543
|
@ -35,8 +35,7 @@ module Capybara
|
||||||
when XPath::Expression
|
when XPath::Expression
|
||||||
raise ArgumentError, 'XPath expressions are not supported for the :class filter with CSS based selectors'
|
raise ArgumentError, 'XPath expressions are not supported for the :class filter with CSS based selectors'
|
||||||
when Regexp
|
when Regexp
|
||||||
strs = Selector::RegexpDisassembler.new(classes).substrings
|
attribute_conditions(class: classes)
|
||||||
strs.map { |str| "[class*='#{str}'#{' i' if classes.casefold?}]" }.join
|
|
||||||
else
|
else
|
||||||
cls = Array(classes).group_by { |cl| cl.start_with? '!' }
|
cls = Array(classes).group_by { |cl| cl.start_with? '!' }
|
||||||
(cls[false].to_a.map { |cl| ".#{Capybara::Selector::CSS.escape(cl)}" } +
|
(cls[false].to_a.map { |cl| ".#{Capybara::Selector::CSS.escape(cl)}" } +
|
||||||
|
|
|
@ -26,10 +26,8 @@ module Capybara
|
||||||
|
|
||||||
def class_conditions(classes)
|
def class_conditions(classes)
|
||||||
case classes
|
case classes
|
||||||
when XPath::Expression
|
when XPath::Expression, Regexp
|
||||||
XPath.attr(:class)[classes]
|
attribute_conditions(class: classes)
|
||||||
when Regexp
|
|
||||||
XPath.attr(:class)[regexp_to_xpath_conditions(classes)]
|
|
||||||
else
|
else
|
||||||
Array(classes).map do |klass|
|
Array(classes).map do |klass|
|
||||||
if klass.start_with?('!')
|
if klass.start_with?('!')
|
||||||
|
|
Loading…
Reference in New Issue