mirror of
https://github.com/teamcapybara/capybara.git
synced 2022-11-09 12:08:07 -05:00
Some more cleanup
This commit is contained in:
parent
620a6e782c
commit
bda4b8dc75
2 changed files with 6 additions and 28 deletions
|
@ -36,7 +36,8 @@ class Capybara::Driver::RackTest < Capybara::Driver::Base
|
|||
|
||||
def set(value)
|
||||
if tag_name == 'input' and type == 'radio'
|
||||
driver.html.xpath("//input[@name=#{Capybara::XPath.escape(self[:name])}]").each { |node| node.remove_attribute("checked") }
|
||||
other_radios_xpath = ::XPath.generate { |x| x.anywhere(:input)[x.attr(:name).equals(self[:name])] }.to_s
|
||||
driver.html.xpath(other_radios_xpath).each { |node| node.remove_attribute("checked") }
|
||||
native['checked'] = 'checked'
|
||||
elsif tag_name == 'input' and type == 'checkbox'
|
||||
if value && !native['checked']
|
||||
|
|
|
@ -1,19 +1,7 @@
|
|||
require 'xpath'
|
||||
|
||||
::XPath::Collection.class_eval do
|
||||
alias_method :paths, :expressions
|
||||
end
|
||||
|
||||
module Capybara
|
||||
|
||||
##
|
||||
#
|
||||
# This is a class for generating XPath queries, use it like this:
|
||||
#
|
||||
# Xpath.text_field('foo').link('blah').to_s
|
||||
#
|
||||
# This will generate an XPath that matches either a text field or a link.
|
||||
#
|
||||
module XPath
|
||||
|
||||
include ::XPath
|
||||
|
@ -53,16 +41,16 @@ module Capybara
|
|||
if options[:with]
|
||||
fillable_field(locator, options)
|
||||
else
|
||||
xpath = descendant(:input, :textarea, :select)[attr(:type).one_of('submit', 'image', 'hidden').inverse]
|
||||
xpath = descendant(:input, :textarea, :select)[~attr(:type).one_of('submit', 'image', 'hidden')]
|
||||
xpath = locate_field(xpath, locator)
|
||||
xpath = xpath[attr(:checked)] if options[:checked]
|
||||
xpath = xpath[attr(:checked).inverse] if options[:unchecked]
|
||||
xpath = xpath[~attr(:checked)] if options[:unchecked]
|
||||
xpath
|
||||
end
|
||||
end
|
||||
|
||||
def fillable_field(locator, options={})
|
||||
xpath = descendant(:input, :textarea)[attr(:type).one_of('submit', 'image', 'radio', 'checkbox', 'hidden', 'file').inverse]
|
||||
xpath = descendant(:input, :textarea)[~attr(:type).one_of('submit', 'image', 'radio', 'checkbox', 'hidden', 'file')]
|
||||
xpath = locate_field(xpath, locator)
|
||||
xpath = xpath[field_value(options[:with])] if options.has_key?(:with)
|
||||
xpath
|
||||
|
@ -120,17 +108,6 @@ module Capybara
|
|||
cell_conditions
|
||||
end
|
||||
|
||||
def escape(string)
|
||||
if string.include?("'")
|
||||
string = string.split("'", -1).map do |substr|
|
||||
"'#{substr}'"
|
||||
end.join(%q{,"'",})
|
||||
"concat(#{string})"
|
||||
else
|
||||
"'#{string}'"
|
||||
end
|
||||
end
|
||||
|
||||
def wrap(path)
|
||||
if path.respond_to?(:to_xpaths)
|
||||
path.to_xpaths
|
||||
|
@ -153,7 +130,7 @@ module Capybara
|
|||
end
|
||||
|
||||
def field_value(value)
|
||||
(text.is(value) & name.equals('textarea')) | (attr(:value).equals(value) & name.equals('textarea').inverse)
|
||||
(text.is(value) & name.equals('textarea')) | (attr(:value).equals(value) & ~name.equals('textarea'))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue