Extract `selected` into filter
This commit is contained in:
parent
9b09d18066
commit
2d1b71cebc
|
@ -14,19 +14,11 @@ module Capybara
|
||||||
return false if options[:with] and not node.value == options[:with]
|
return false if options[:with] and not node.value == options[:with]
|
||||||
return false if options[:checked] and not node.checked?
|
return false if options[:checked] and not node.checked?
|
||||||
return false if options[:unchecked] and node.checked?
|
return false if options[:unchecked] and node.checked?
|
||||||
return false if options[:selected] and not has_selected_options?(node, options[:selected])
|
|
||||||
selector.custom_filters.each do |name, block|
|
selector.custom_filters.each do |name, block|
|
||||||
return false if options.has_key?(name) and not block.call(node, options[name])
|
return false if options.has_key?(name) and not block.call(node, options[name])
|
||||||
end
|
end
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
|
||||||
|
|
||||||
def has_selected_options?(node, expected)
|
|
||||||
actual = node.all(:xpath, './/option').select { |option| option.selected? }.map { |option| option.text }
|
|
||||||
(expected - actual).empty?
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
|
@ -164,6 +156,10 @@ Capybara.add_selector(:select) do
|
||||||
xpath { |locator, xpath_options| XPath::HTML.select(locator, xpath_options) }
|
xpath { |locator, xpath_options| XPath::HTML.select(locator, xpath_options) }
|
||||||
failure_message { |node, selector| "no select box with id, name, or label '#{selector.locator}' found" }
|
failure_message { |node, selector| "no select box with id, name, or label '#{selector.locator}' found" }
|
||||||
filter(:options) { |node, options| options.all? { |option| node.first(:option, option) } }
|
filter(:options) { |node, options| options.all? { |option| node.first(:option, option) } }
|
||||||
|
filter(:selected) do |node, selected|
|
||||||
|
actual = node.all(:xpath, './/option').select { |option| option.selected? }.map { |option| option.text }
|
||||||
|
(selected - actual).empty?
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
Capybara.add_selector(:option) do
|
Capybara.add_selector(:option) do
|
||||||
|
|
|
@ -107,7 +107,7 @@ shared_examples_for "find" do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "with custom selector with custom filter", :focus => true do
|
context "with custom selector with custom filter" do
|
||||||
before do
|
before do
|
||||||
Capybara.add_selector(:monkey) do
|
Capybara.add_selector(:monkey) do
|
||||||
xpath { |num| ".//*[contains(@id, 'monkey')][#{num}]" }
|
xpath { |num| ".//*[contains(@id, 'monkey')][#{num}]" }
|
||||||
|
|
Loading…
Reference in New Issue