Whitespace!

This commit is contained in:
Jonas Nicklas 2010-01-01 17:48:39 +01:00
parent 8241018282
commit 6a3abbe006
6 changed files with 35 additions and 39 deletions

View File

@ -1,7 +1,7 @@
module Capybara
class Node
include Searchable
attr_reader :driver, :node
def initialize(driver, node)
@ -49,13 +49,13 @@ module Capybara
raise NotSupportedByDriverError
end
private
private
def all_unfiltered(locator)
nodes = XPath.wrap(locator).scope(path).paths.map do |path|
driver.find(path)
end.flatten
end
end
end

View File

@ -6,6 +6,6 @@ Capybara.app = Rack::Builder.new do
use Rails::Rack::Static
run ActionController::Dispatcher.new
end
end.to_app
end.to_app
Capybara.asset_root = Rails.root.join('public')

View File

@ -22,7 +22,6 @@ class Capybara::Server
end
end
attr_reader :app, :port
def initialize(app)

View File

@ -3,16 +3,15 @@ require 'capybara/wait_until'
module Capybara
class Session
include Searchable
attr_reader :mode, :app
def initialize(mode, app)
@mode = mode
@app = app
end
def driver
@driver ||= case mode
when :rack_test
Capybara::Driver::RackTest.new(app)
@ -30,11 +29,11 @@ module Capybara
def current_url
driver.current_url
end
def response_headers
driver.response_headers
end
def visit(path)
driver.visit(path)
end
@ -56,9 +55,7 @@ module Capybara
def drag(source_locator, target_locator)
source = locate(source_locator, "drag source '#{source_locator}' not found on page")
target = locate(target_locator, "drag target '#{target_locator}' not found on page")
source.drag_to(target)
end
@ -133,11 +130,11 @@ module Capybara
raise Capybara::ElementNotFound, fail_msg || "Unable to locate '#{locator}'" unless node
return node
end
def wait_until(timeout = Capybara.default_wait_time)
WaitUntil.timeout(timeout) { yield }
end
def evaluate_script(script)
driver.evaluate_script(script)
end
@ -149,7 +146,7 @@ module Capybara
driver.find(path)
end.flatten
end
def current_scope
scopes.join('')
end

View File

@ -1,23 +1,23 @@
module Capybara
#Provides timeout similar to standard library Timeout, but avoids threads
class WaitUntil
class << self
def timeout(seconds = 1, &block)
start_time = Time.now
result = nil
until result
until result
return result if result = yield
if (Time.now - start_time) > seconds
raise TimeoutError
end
end
end
end
end
end
end
end
end

View File

@ -8,7 +8,7 @@ module Capybara
Nokogiri::CSS.xpath_for(css).first
end
alias_method :for_css, :from_css
def wrap(path)
if path.is_a?(self)
path
@ -16,7 +16,7 @@ module Capybara
new(path.to_s)
end
end
def respond_to?(method)
new.respond_to?(method)
end
@ -39,23 +39,23 @@ module Capybara
def fillable_field(locator)
text_field(locator).password_field(locator).text_area(locator)
end
def content(locator)
append("/descendant-or-self::*[contains(.,#{s(locator)})]")
end
def table(locator)
append("//table[@id=#{s(locator)} or contains(caption,#{s(locator)})]")
end
def fieldset(locator)
append("//fieldset[@id=#{s(locator)} or contains(legend,#{s(locator)})]")
end
def link(locator)
append("//a[@id=#{s(locator)} or contains(.,#{s(locator)}) or @title=#{s(locator)}]")
end
def button(locator)
xpath = append("//input[@type='submit' or @type='image'][@id=#{s(locator)} or contains(@value,#{s(locator)})]")
xpath.append("//button[@id=#{s(locator)} or contains(@value,#{s(locator)}) or contains(.,#{s(locator)})]")
@ -88,7 +88,7 @@ module Capybara
def file_field(locator)
add_field(locator, "//input[@type='file']")
end
def scope(scope)
XPath.new(*paths.map { |p| scope + p })
end
@ -96,24 +96,24 @@ module Capybara
def to_s
@paths.join(' | ')
end
def append(path)
XPath.new(*[@paths, XPath.wrap(path).paths].flatten)
end
def prepend(path)
XPath.new(*[XPath.wrap(path).paths, @paths].flatten)
end
protected
def add_field(locator, field)
xpath = append("#{field}[@id=#{s(locator)}]")
xpath = xpath.append("#{field}[@id=//label[contains(.,#{s(locator)})]/@for]")
xpath = xpath.append("//label[contains(.,#{s(locator)})]#{field}")
xpath.prepend("#{field}[@id=//label[text()=#{s(locator)}]/@for]")
end
# Sanitize a String for putting it into an xpath query
def s(string)
if string.include?("'")
@ -124,7 +124,7 @@ module Capybara
else
"'#{string}'"
end
end
end