1
0
Fork 0
mirror of https://github.com/teamcapybara/capybara.git synced 2022-11-09 12:08:07 -05:00

Make checked and unchecked into filters

This commit is contained in:
Jonas Nicklas 2012-01-02 17:26:23 +01:00
parent 2d1b71cebc
commit dd7123f0b0

View file

@ -12,8 +12,6 @@ module Capybara
return false if options[:text] and not node.text.match(options[:text]) return false if options[:text] and not node.text.match(options[:text])
return false if options[:visible] and not node.visible? return false if options[:visible] and not node.visible?
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[:unchecked] and node.checked?
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
@ -115,6 +113,8 @@ end
Capybara.add_selector(:field) do Capybara.add_selector(:field) do
xpath { |locator| XPath::HTML.field(locator) } xpath { |locator| XPath::HTML.field(locator) }
filter(:checked) { |node, value| not(value ^ node.checked?) }
filter(:unchecked) { |node, value| (value ^ node.checked?) }
end end
Capybara.add_selector(:fieldset) do Capybara.add_selector(:fieldset) do
@ -145,11 +145,15 @@ end
Capybara.add_selector(:radio_button) do Capybara.add_selector(:radio_button) do
xpath { |locator, xpath_options| XPath::HTML.radio_button(locator, xpath_options) } xpath { |locator, xpath_options| XPath::HTML.radio_button(locator, xpath_options) }
failure_message { |node, selector| "no radio button with id, name, or label '#{selector.locator}' found" } failure_message { |node, selector| "no radio button with id, name, or label '#{selector.locator}' found" }
filter(:checked) { |node, value| not(value ^ node.checked?) }
filter(:unchecked) { |node, value| (value ^ node.checked?) }
end end
Capybara.add_selector(:checkbox) do Capybara.add_selector(:checkbox) do
xpath { |locator, xpath_options| XPath::HTML.checkbox(locator, xpath_options) } xpath { |locator, xpath_options| XPath::HTML.checkbox(locator, xpath_options) }
failure_message { |node, selector| "no checkbox with id, name, or label '#{selector.locator}' found" } failure_message { |node, selector| "no checkbox with id, name, or label '#{selector.locator}' found" }
filter(:checked) { |node, value| not(value ^ node.checked?) }
filter(:unchecked) { |node, value| (value ^ node.checked?) }
end end
Capybara.add_selector(:select) do Capybara.add_selector(:select) do