Permalink
Browse files

Follow new capybara driver naming/module conventions

  • Loading branch information...
jferris committed Jul 8, 2012
1 parent 9202683 commit 259a38f206c2c06ed4bba285e7a36411ab3b492f
View
@@ -1,5 +1,5 @@
$:.push File.expand_path("../lib", __FILE__)
-require "capybara/driver/webkit/version"
+require "capybara/webkit/version"
Gem::Specification.new do |s|
s.name = "capybara-webkit"
@@ -1,157 +0,0 @@
-require "capybara"
-require "capybara/driver/webkit/version"
-require "capybara/driver/webkit/node"
-require "capybara/driver/webkit/connection"
-require "capybara/driver/webkit/browser"
-require "capybara/driver/webkit/socket_debugger"
-require "capybara/driver/webkit/cookie_jar"
-
-class Capybara::Driver::Webkit
- class WebkitInvalidResponseError < StandardError
- end
-
- class WebkitNoResponseError < StandardError
- end
-
- class NodeNotAttachedError < Capybara::ElementNotFound
- end
-
- attr_reader :browser
-
- def initialize(app, options={})
- @app = app
- @options = options
- @rack_server = Capybara::Server.new(@app)
- @rack_server.boot if Capybara.run_server
- @browser = options[:browser] || Browser.new(Connection.new(options))
- end
-
- def enable_logging
- browser.enable_logging
- end
-
- def current_url
- browser.current_url
- end
-
- def requested_url
- browser.requested_url
- end
-
- def visit(path)
- browser.visit(url(path))
- end
-
- def find(query)
- browser.find(query).map { |native| Node.new(self, native) }
- end
-
- def source
- browser.source
- end
-
- def body
- browser.body
- end
-
- def header(key, value)
- browser.header(key, value)
- end
-
- def execute_script(script)
- value = browser.execute_script script
- value.empty? ? nil : value
- end
-
- def evaluate_script(script)
- browser.evaluate_script script
- end
-
- def console_messages
- browser.console_messages
- end
-
- def error_messages
- browser.error_messages
- end
-
- def response_headers
- browser.response_headers
- end
-
- def status_code
- browser.status_code
- end
-
- def resize_window(width, height)
- browser.resize_window(width, height)
- end
-
- def within_frame(frame_id_or_index)
- browser.frame_focus(frame_id_or_index)
- begin
- yield
- ensure
- browser.frame_focus
- end
- end
-
- def within_window(selector)
- current_window = window_handle
- browser.window_focus(selector)
- begin
- yield
- ensure
- browser.window_focus(current_window)
- end
- end
-
- def window_handles
- browser.get_window_handles
- end
-
- def window_handle
- browser.get_window_handle
- end
-
- def wait?
- true
- end
-
- def wait_until(*args)
- end
-
- def reset!
- browser.reset!
- end
-
- def has_shortcircuit_timeout?
- false
- end
-
- def render(path, options={})
- options[:width] ||= 1000
- options[:height] ||= 10
-
- browser.render path, options[:width], options[:height]
- end
-
- def server_port
- @rack_server.port
- end
-
- def cookies
- @cookie_jar ||= CookieJar.new(browser)
- end
-
- def invalid_element_errors
- []
- end
-
- private
-
- def url(path)
- @rack_server.url(path)
- end
-end
-
View
@@ -1,12 +1,18 @@
require "capybara"
-require "capybara/driver/webkit"
+
+module Capybara
+ module Webkit
+ end
+end
+
+require "capybara/webkit/driver"
Capybara.register_driver :webkit do |app|
- Capybara::Driver::Webkit.new(app)
+ Capybara::Webkit::Driver.new(app)
end
Capybara.register_driver :webkit_debug do |app|
- driver = Capybara::Driver::Webkit.new(app)
+ driver = Capybara::Webkit::Driver.new(app)
driver.enable_logging
driver
end
@@ -1,6 +1,6 @@
require 'json'
-class Capybara::Driver::Webkit
+module Capybara::Webkit
class Browser
def initialize(connection)
@connection = connection
@@ -161,9 +161,9 @@ def check
result.strip! if result
if result.nil?
- raise WebkitNoResponseError, "No response received from the server."
+ raise NoResponseError, "No response received from the server."
elsif result != 'ok'
- raise WebkitInvalidResponseError, read_response
+ raise InvalidResponseError, read_response
end
result
@@ -2,9 +2,9 @@
require 'timeout'
require 'thread'
-class Capybara::Driver::Webkit
+module Capybara::Webkit
class Connection
- SERVER_PATH = File.expand_path("../../../../../bin/webkit_server", __FILE__)
+ SERVER_PATH = File.expand_path("../../../../bin/webkit_server", __FILE__)
WEBKIT_SERVER_START_TIMEOUT = 15
attr_reader :port
@@ -3,7 +3,7 @@
# A simple cookie jar implementation.
# Does not take special cookie attributes
# into account like expire, max-age, httponly, secure
-class Capybara::Driver::Webkit::CookieJar
+class Capybara::Webkit::CookieJar
attr_reader :browser
def initialize(browser)
@@ -0,0 +1,150 @@
+require "capybara"
+require "capybara/webkit/version"
+require "capybara/webkit/node"
+require "capybara/webkit/connection"
+require "capybara/webkit/browser"
+require "capybara/webkit/socket_debugger"
+require "capybara/webkit/cookie_jar"
+require "capybara/webkit/errors"
+
+module Capybara::Webkit
+ class Driver
+ attr_reader :browser
+
+ def initialize(app, options={})
+ @app = app
+ @options = options
+ @rack_server = Capybara::Server.new(@app)
+ @rack_server.boot if Capybara.run_server
+ @browser = options[:browser] || Browser.new(Connection.new(options))
+ end
+
+ def enable_logging
+ browser.enable_logging
+ end
+
+ def current_url
+ browser.current_url
+ end
+
+ def requested_url
+ browser.requested_url
+ end
+
+ def visit(path)
+ browser.visit(url(path))
+ end
+
+ def find(query)
+ browser.find(query).map { |native| Node.new(self, native) }
+ end
+
+ def source
+ browser.source
+ end
+
+ def body
+ browser.body
+ end
+
+ def header(key, value)
+ browser.header(key, value)
+ end
+
+ def execute_script(script)
+ value = browser.execute_script script
+ value.empty? ? nil : value
+ end
+
+ def evaluate_script(script)
+ browser.evaluate_script script
+ end
+
+ def console_messages
+ browser.console_messages
+ end
+
+ def error_messages
+ browser.error_messages
+ end
+
+ def response_headers
+ browser.response_headers
+ end
+
+ def status_code
+ browser.status_code
+ end
+
+ def resize_window(width, height)
+ browser.resize_window(width, height)
+ end
+
+ def within_frame(frame_id_or_index)
+ browser.frame_focus(frame_id_or_index)
+ begin
+ yield
+ ensure
+ browser.frame_focus
+ end
+ end
+
+ def within_window(selector)
+ current_window = window_handle
+ browser.window_focus(selector)
+ begin
+ yield
+ ensure
+ browser.window_focus(current_window)
+ end
+ end
+
+ def window_handles
+ browser.get_window_handles
+ end
+
+ def window_handle
+ browser.get_window_handle
+ end
+
+ def wait?
+ true
+ end
+
+ def wait_until(*args)
+ end
+
+ def reset!
+ browser.reset!
+ end
+
+ def has_shortcircuit_timeout?
+ false
+ end
+
+ def render(path, options={})
+ options[:width] ||= 1000
+ options[:height] ||= 10
+
+ browser.render path, options[:width], options[:height]
+ end
+
+ def server_port
+ @rack_server.port
+ end
+
+ def cookies
+ @cookie_jar ||= CookieJar.new(browser)
+ end
+
+ def invalid_element_errors
+ []
+ end
+
+ private
+
+ def url(path)
+ @rack_server.url(path)
+ end
+ end
+end
@@ -0,0 +1,10 @@
+module Capybara::Webkit
+ class InvalidResponseError < StandardError
+ end
+
+ class NoResponseError < StandardError
+ end
+
+ class NodeNotAttachedError < Capybara::ElementNotFound
+ end
+end
Oops, something went wrong.

0 comments on commit 259a38f

Please sign in to comment.