filter type should not need to specify value - default to true
This commit is contained in:
parent
64571d0d9f
commit
d6972e79a7
|
@ -2,10 +2,10 @@
|
||||||
require 'capybara/selector/selector'
|
require 'capybara/selector/selector'
|
||||||
|
|
||||||
Capybara::Selector::FilterSet.add(:_field) do
|
Capybara::Selector::FilterSet.add(:_field) do
|
||||||
filter(:checked, boolean: true) { |node, value| not(value ^ node.checked?) }
|
filter(:checked, :boolean) { |node, value| not(value ^ node.checked?) }
|
||||||
filter(:unchecked, boolean: true) { |node, value| (value ^ node.checked?) }
|
filter(:unchecked, :boolean) { |node, value| (value ^ node.checked?) }
|
||||||
filter(:disabled, default: false, boolean: true, skip_if: :all) { |node, value| not(value ^ node.disabled?) }
|
filter(:disabled, :boolean, default: false, skip_if: :all) { |node, value| not(value ^ node.disabled?) }
|
||||||
filter(:multiple, boolean: true) { |node, value| !(value ^ node.multiple?) }
|
filter(:multiple, :boolean) { |node, value| !(value ^ node.multiple?) }
|
||||||
|
|
||||||
describe do |options|
|
describe do |options|
|
||||||
desc, states = String.new, []
|
desc, states = String.new, []
|
||||||
|
@ -47,7 +47,7 @@ Capybara.add_selector(:field) do
|
||||||
|
|
||||||
filter_set(:_field) # checked/unchecked/disabled/multiple
|
filter_set(:_field) # checked/unchecked/disabled/multiple
|
||||||
|
|
||||||
filter(:readonly, boolean: true) { |node, value| not(value ^ node.readonly?) }
|
filter(:readonly, :boolean) { |node, value| not(value ^ node.readonly?) }
|
||||||
filter(:with) do |node, with|
|
filter(:with) do |node, with|
|
||||||
with.is_a?(Regexp) ? node.value =~ with : node.value == with.to_s
|
with.is_a?(Regexp) ? node.value =~ with : node.value == with.to_s
|
||||||
end
|
end
|
||||||
|
@ -126,7 +126,7 @@ Capybara.add_selector(:button) do
|
||||||
res_xpath
|
res_xpath
|
||||||
end
|
end
|
||||||
|
|
||||||
filter(:disabled, default: false, boolean: true, skip_if: :all) { |node, value| not(value ^ node.disabled?) }
|
filter(:disabled, :boolean, default: false, skip_if: :all) { |node, value| not(value ^ node.disabled?) }
|
||||||
|
|
||||||
describe do |options|
|
describe do |options|
|
||||||
desc = String.new
|
desc = String.new
|
||||||
|
@ -142,7 +142,7 @@ Capybara.add_selector(:link_or_button) do
|
||||||
self.class.all.values_at(:link, :button).map {|selector| selector.xpath.call(locator, options)}.reduce(:+)
|
self.class.all.values_at(:link, :button).map {|selector| selector.xpath.call(locator, options)}.reduce(:+)
|
||||||
end
|
end
|
||||||
|
|
||||||
filter(:disabled, default: false, boolean: true, skip_if: :all) { |node, value| node.tag_name == "a" or not(value ^ node.disabled?) }
|
filter(:disabled, :boolean, default: false, skip_if: :all) { |node, value| node.tag_name == "a" or not(value ^ node.disabled?) }
|
||||||
|
|
||||||
describe { |options| " that is disabled" if options[:disabled] }
|
describe { |options| " that is disabled" if options[:disabled] }
|
||||||
end
|
end
|
||||||
|
@ -246,8 +246,8 @@ Capybara.add_selector(:option) do
|
||||||
xpath
|
xpath
|
||||||
end
|
end
|
||||||
|
|
||||||
filter(:disabled, boolean: true) { |node, value| not(value ^ node.disabled?) }
|
filter(:disabled, :boolean) { |node, value| not(value ^ node.disabled?) }
|
||||||
filter(:selected, boolean: true) { |node, value| not(value ^ node.selected?) }
|
filter(:selected, :boolean) { |node, value| not(value ^ node.selected?) }
|
||||||
|
|
||||||
describe do |options|
|
describe do |options|
|
||||||
desc = String.new
|
desc = String.new
|
||||||
|
|
|
@ -12,7 +12,9 @@ module Capybara
|
||||||
instance_eval(&block)
|
instance_eval(&block)
|
||||||
end
|
end
|
||||||
|
|
||||||
def filter(name, options={}, &block)
|
def filter(name, *types_and_options, &block)
|
||||||
|
options = types_and_options.last.is_a?(Hash) ? types_and_options.pop.dup : {}
|
||||||
|
types_and_options.each { |k| options[k] = true}
|
||||||
filters[name] = Filter.new(name, block, options)
|
filters[name] = Filter.new(name, block, options)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -77,7 +77,9 @@ module Capybara
|
||||||
@match and @match.call(locator)
|
@match and @match.call(locator)
|
||||||
end
|
end
|
||||||
|
|
||||||
def filter(name, options={}, &block)
|
def filter(name, *types_and_options, &block)
|
||||||
|
options = types_and_options.last.is_a?(Hash) ? types_and_options.pop.dup : {}
|
||||||
|
types_and_options.each { |k| options[k] = true}
|
||||||
custom_filters[name] = Filter.new(name, block, options)
|
custom_filters[name] = Filter.new(name, block, options)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue