Skip to content
Browse files

Follow new capybara driver naming/module conventions

  • Loading branch information...
1 parent 9202683 commit 259a38f206c2c06ed4bba285e7a36411ab3b492f @jferris jferris committed Jul 8, 2012
View
2 capybara-webkit.gemspec
@@ -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"
View
157 lib/capybara/driver/webkit.rb
@@ -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
12 lib/capybara/webkit.rb
@@ -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
View
6 lib/capybara/driver/webkit/browser.rb → lib/capybara/webkit/browser.rb
@@ -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
View
4 lib/capybara/driver/webkit/connection.rb → lib/capybara/webkit/connection.rb
@@ -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
View
2 lib/capybara/driver/webkit/cookie_jar.rb → lib/capybara/webkit/cookie_jar.rb
@@ -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)
View
150 lib/capybara/webkit/driver.rb
@@ -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
View
10 lib/capybara/webkit/errors.rb
@@ -0,0 +1,10 @@
+module Capybara::Webkit
+ class InvalidResponseError < StandardError
+ end
+
+ class NoResponseError < StandardError
+ end
+
+ class NodeNotAttachedError < Capybara::ElementNotFound
+ end
+end
View
4 lib/capybara/driver/webkit/node.rb → lib/capybara/webkit/node.rb
@@ -1,4 +1,4 @@
-class Capybara::Driver::Webkit
+module Capybara::Webkit
class Node < Capybara::Driver::Node
NBSP = "\xC2\xA0"
NBSP.force_encoding("UTF-8") if NBSP.respond_to?(:force_encoding)
@@ -91,7 +91,7 @@ def invoke(name, *args)
if allow_unattached_nodes? || attached?
browser.command "Node", name, native, *args
else
- raise Capybara::Driver::Webkit::NodeNotAttachedError
+ raise Capybara::Webkit::NodeNotAttachedError
end
end
View
2 ...capybara/driver/webkit/socket_debugger.rb → lib/capybara/webkit/socket_debugger.rb
@@ -1,6 +1,6 @@
# Wraps the TCP socket and prints data sent and received. Used for debugging
# the wire protocol. You can use this by passing a :socket_class to Browser.
-class Capybara::Driver::Webkit
+module Capybara::Webkit
class SocketDebugger
def self.open(host, port)
real_socket = TCPSocket.open(host, port)
View
0 lib/capybara/driver/webkit/version.rb → lib/capybara/webkit/version.rb
File renamed without changes.
View
12 spec/browser_spec.rb
@@ -1,20 +1,20 @@
require 'spec_helper'
require 'self_signed_ssl_cert'
require 'stringio'
-require 'capybara/driver/webkit'
+require 'capybara/webkit/driver'
require 'socket'
require 'base64'
-describe Capybara::Driver::Webkit::Browser do
+describe Capybara::Webkit::Browser do
- let(:browser) { Capybara::Driver::Webkit::Browser.new(Capybara::Driver::Webkit::Connection.new) }
+ let(:browser) { Capybara::Webkit::Browser.new(Capybara::Webkit::Connection.new) }
let(:browser_ignore_ssl_err) do
- Capybara::Driver::Webkit::Browser.new(Capybara::Driver::Webkit::Connection.new).tap do |browser|
+ Capybara::Webkit::Browser.new(Capybara::Webkit::Connection.new).tap do |browser|
browser.ignore_ssl_errors
end
end
let(:browser_skip_images) do
- Capybara::Driver::Webkit::Browser.new(Capybara::Driver::Webkit::Connection.new).tap do |browser|
+ Capybara::Webkit::Browser.new(Capybara::Webkit::Connection.new).tap do |browser|
browser.set_skip_image_loading(true)
end
end
@@ -254,7 +254,7 @@
connection.stub(:gets).and_return("ok\n", "0\n")
connection.stub(:read).and_raise(StandardError.new("tried to read empty response"))
- browser = Capybara::Driver::Webkit::Browser.new(connection)
+ browser = Capybara::Webkit::Browser.new(connection)
expect { browser.visit("/") }.not_to raise_error(/empty response/)
end
View
10 spec/connection_spec.rb
@@ -1,7 +1,7 @@
require 'spec_helper'
-require 'capybara/driver/webkit/connection'
+require 'capybara/webkit/connection'
-describe Capybara::Driver::Webkit::Connection do
+describe Capybara::Webkit::Connection do
it "boots a server to talk to" do
url = @rack_server.url("/")
connection.puts "Visit"
@@ -20,7 +20,7 @@
it 'forwards stdout to the given IO object' do
io = StringIO.new
- redirected_connection = Capybara::Driver::Webkit::Connection.new(:stdout => io)
+ redirected_connection = Capybara::Webkit::Connection.new(:stdout => io)
script = 'console.log("hello world")'
redirected_connection.puts "Execute"
redirected_connection.puts 1
@@ -35,11 +35,11 @@
end
it "chooses a new port number for a new connection" do
- new_connection = Capybara::Driver::Webkit::Connection.new
+ new_connection = Capybara::Webkit::Connection.new
new_connection.port.should_not == connection.port
end
- let(:connection) { Capybara::Driver::Webkit::Connection.new }
+ let(:connection) { Capybara::Webkit::Connection.new }
before(:all) do
@app = lambda do |env|
View
6 spec/cookie_jar_spec.rb
@@ -1,7 +1,7 @@
require 'spec_helper'
-require 'capybara/driver/webkit/cookie_jar'
+require 'capybara/webkit/cookie_jar'
-describe Capybara::Driver::Webkit::CookieJar do
+describe Capybara::Webkit::CookieJar do
let(:browser) {
browser = double("Browser")
browser.stub(:get_cookies) { [
@@ -13,7 +13,7 @@
browser
}
- subject { Capybara::Driver::Webkit::CookieJar.new(browser) }
+ subject { Capybara::Webkit::CookieJar.new(browser) }
describe "#find" do
it "returns a cookie object" do
View
6 spec/driver_rendering_spec.rb
@@ -1,8 +1,8 @@
require 'spec_helper'
-require 'capybara/driver/webkit'
+require 'capybara/webkit/driver'
require 'mini_magick'
-describe Capybara::Driver::Webkit, "rendering an image" do
+describe Capybara::Webkit::Driver, "rendering an image" do
before(:all) do
# Set up the tmp directory and file name
@@ -23,7 +23,7 @@
[body]]
end
- @driver = Capybara::Driver::Webkit.new(app, :browser => $webkit_browser)
+ @driver = Capybara::Webkit::Driver.new(app, :browser => $webkit_browser)
@driver.visit("/hello/world?success=true")
end
View
6 spec/driver_resize_window_spec.rb
@@ -1,7 +1,7 @@
require 'spec_helper'
-require 'capybara/driver/webkit'
+require 'capybara/webkit/driver'
-describe Capybara::Driver::Webkit, "#resize_window(width, height)" do
+describe Capybara::Webkit::Driver, "#resize_window(width, height)" do
before(:all) do
app = lambda do |env|
@@ -27,7 +27,7 @@
]
end
- @driver = Capybara::Driver::Webkit.new(app, :browser => $webkit_browser)
+ @driver = Capybara::Webkit::Driver.new(app, :browser => $webkit_browser)
end
DEFAULT_DIMENTIONS = "[1680x1050]"
View
42 spec/driver_spec.rb
@@ -1,9 +1,9 @@
require 'spec_helper'
-require 'capybara/driver/webkit'
+require 'capybara/webkit/driver'
require 'base64'
-describe Capybara::Driver::Webkit do
- subject { Capybara::Driver::Webkit.new(@app, :browser => $webkit_browser) }
+describe Capybara::Webkit::Driver do
+ subject { Capybara::Webkit::Driver.new(@app, :browser => $webkit_browser) }
before do
subject.reset!
subject.visit("/hello/world?success=true")
@@ -59,12 +59,12 @@
it "raises error for missing frame by index" do
expect { subject.within_frame(1) { } }.
- to raise_error(Capybara::Driver::Webkit::WebkitInvalidResponseError)
+ to raise_error(Capybara::Webkit::InvalidResponseError)
end
it "raise_error for missing frame by id" do
expect { subject.within_frame("foo") { } }.
- to raise_error(Capybara::Driver::Webkit::WebkitInvalidResponseError)
+ to raise_error(Capybara::Webkit::InvalidResponseError)
end
it "returns an attribute's value" do
@@ -132,7 +132,7 @@
end
it "raises error whose message references the actual missing url" do
- expect { subject.visit("/outer") }.to raise_error(Capybara::Driver::Webkit::WebkitInvalidResponseError, /inner-not-found/)
+ expect { subject.visit("/outer") }.to raise_error(Capybara::Webkit::InvalidResponseError, /inner-not-found/)
end
end
@@ -250,7 +250,7 @@
it "raises an error for an invalid xpath query" do
expect { subject.find("totally invalid salad") }.
- to raise_error(Capybara::Driver::Webkit::WebkitInvalidResponseError, /xpath/i)
+ to raise_error(Capybara::Webkit::InvalidResponseError, /xpath/i)
end
it "returns an attribute's value" do
@@ -357,7 +357,7 @@
it "raises an error for failing Javascript" do
expect { subject.execute_script(%<invalid salad>) }.
- to raise_error(Capybara::Driver::Webkit::WebkitInvalidResponseError)
+ to raise_error(Capybara::Webkit::InvalidResponseError)
end
it "doesn't raise an error for Javascript that doesn't return anything" do
@@ -881,7 +881,7 @@
wait_for_error_to_complete
subject.find("//body")
}.
- to raise_error(Capybara::Driver::Webkit::WebkitInvalidResponseError, %r{/error})
+ to raise_error(Capybara::Webkit::InvalidResponseError, %r{/error})
end
def wait_for_error_to_complete
@@ -912,7 +912,7 @@ def wait_for_error_to_complete
it "raises a webkit error and then continues" do
subject.find("//input").first.click
- expect { subject.find("//p") }.to raise_error(Capybara::Driver::Webkit::WebkitInvalidResponseError)
+ expect { subject.find("//p") }.to raise_error(Capybara::Webkit::InvalidResponseError)
subject.visit("/")
subject.find("//p").first.text.should == "hello"
end
@@ -1015,7 +1015,7 @@ def wait_for_error_to_complete
expect {
subject.find("//body")
}.
- to raise_error(Capybara::Driver::Webkit::WebkitNoResponseError, %r{response})
+ to raise_error(Capybara::Webkit::NoResponseError, %r{response})
make_the_server_come_back
end
@@ -1121,12 +1121,12 @@ def echoed_cookie
end
context "with socket debugger" do
- let(:socket_debugger_class){ Capybara::Driver::Webkit::SocketDebugger }
+ let(:socket_debugger_class){ Capybara::Webkit::SocketDebugger }
let(:browser_with_debugger){
- connection = Capybara::Driver::Webkit::Connection.new(:socket_class => socket_debugger_class)
- Capybara::Driver::Webkit::Browser.new(connection)
+ connection = Capybara::Webkit::Connection.new(:socket_class => socket_debugger_class)
+ Capybara::Webkit::Browser.new(connection)
}
- let(:driver_with_debugger){ Capybara::Driver::Webkit.new(@app, :browser => browser_with_debugger) }
+ let(:driver_with_debugger){ Capybara::Webkit::Driver.new(@app, :browser => browser_with_debugger) }
before(:all) do
@app = lambda do |env|
@@ -1657,7 +1657,7 @@ def which_for(character)
it "raises an error if the window is not found" do
expect { subject.within_window('myWindowDoesNotExist') }.
- to raise_error(Capybara::Driver::Webkit::WebkitInvalidResponseError)
+ to raise_error(Capybara::Webkit::InvalidResponseError)
end
it "has a number of window handles equal to the number of open windows" do
@@ -1740,7 +1740,7 @@ def which_for(character)
subject.visit("/outer")
sleep 1
subject.find("//body")
- end.to raise_error(Capybara::Driver::Webkit::WebkitInvalidResponseError)
+ end.to raise_error(Capybara::Webkit::InvalidResponseError)
end
end
@@ -1789,10 +1789,10 @@ def which_for(character)
end
let(:driver) do
- command = "#{Capybara::Driver::Webkit::Connection::SERVER_PATH} 2>&1"
- connection = Capybara::Driver::Webkit::Connection.new(:command => command, :stdout => output)
- browser = Capybara::Driver::Webkit::Browser.new(connection)
- Capybara::Driver::Webkit.new(@app, :browser => browser)
+ command = "#{Capybara::Webkit::Connection::SERVER_PATH} 2>&1"
+ connection = Capybara::Webkit::Connection.new(:command => command, :stdout => output)
+ browser = Capybara::Webkit::Browser.new(connection)
+ Capybara::Webkit::Driver.new(@app, :browser => browser)
end
let(:output) { StringIO.new }
View
6 spec/integration/driver_spec.rb
@@ -1,9 +1,9 @@
require 'spec_helper'
-require 'capybara/driver/webkit'
+require 'capybara/webkit/driver'
-describe Capybara::Driver::Webkit do
+describe Capybara::Webkit::Driver do
before do
- @driver = Capybara::Driver::Webkit.new(TestApp, :browser => $webkit_browser)
+ @driver = Capybara::Webkit::Driver.new(TestApp, :browser => $webkit_browser)
end
it_should_behave_like "driver"
View
9 spec/spec_helper.rb
@@ -22,13 +22,12 @@
require File.join(spec_dir, "spec_helper")
-require 'capybara/driver/webkit/connection'
-require 'capybara/driver/webkit/browser'
-connection = Capybara::Driver::Webkit::Connection.new(:socket_class => TCPSocket, :stdout => nil)
-$webkit_browser = Capybara::Driver::Webkit::Browser.new(connection)
+require 'capybara/webkit'
+connection = Capybara::Webkit::Connection.new(:socket_class => TCPSocket, :stdout => nil)
+$webkit_browser = Capybara::Webkit::Browser.new(connection)
Capybara.register_driver :reusable_webkit do |app|
- Capybara::Driver::Webkit.new(app, :browser => $webkit_browser)
+ Capybara::Webkit::Driver.new(app, :browser => $webkit_browser)
end
def with_env_vars(vars)

0 comments on commit 259a38f

Please sign in to comment.
Something went wrong with that request. Please try again.