mirror of
https://github.com/teamcapybara/capybara.git
synced 2022-11-09 12:08:07 -05:00
renamed to capybara
This commit is contained in:
parent
6f1556254b
commit
6b099a4a33
31 changed files with 186 additions and 186 deletions
26
Manifest.txt
26
Manifest.txt
|
@ -3,19 +3,19 @@ Manifest.txt
|
|||
README.rdoc
|
||||
Rakefile
|
||||
examples/webcat.rb
|
||||
lib/webcat.rb
|
||||
lib/webcat/core_ext/tcp_socket.rb
|
||||
lib/webcat/cucumber.rb
|
||||
lib/webcat/driver/culerity_driver.rb
|
||||
lib/webcat/driver/firewatir_driver.rb
|
||||
lib/webcat/driver/rack_test_driver.rb
|
||||
lib/webcat/driver/safariwatir_driver.rb
|
||||
lib/webcat/driver/selenium_driver.rb
|
||||
lib/webcat/dsl.rb
|
||||
lib/webcat/rails.rb
|
||||
lib/webcat/save_and_open_page.rb
|
||||
lib/webcat/server.rb
|
||||
lib/webcat/session.rb
|
||||
lib/capybara.rb
|
||||
lib/capybara/core_ext/tcp_socket.rb
|
||||
lib/capybara/cucumber.rb
|
||||
lib/capybara/driver/culerity_driver.rb
|
||||
lib/capybara/driver/firewatir_driver.rb
|
||||
lib/capybara/driver/rack_test_driver.rb
|
||||
lib/capybara/driver/safariwatir_driver.rb
|
||||
lib/capybara/driver/selenium_driver.rb
|
||||
lib/capybara/dsl.rb
|
||||
lib/capybara/rails.rb
|
||||
lib/capybara/save_and_open_page.rb
|
||||
lib/capybara/server.rb
|
||||
lib/capybara/session.rb
|
||||
script/console
|
||||
script/destroy
|
||||
script/generate
|
||||
|
|
30
README.rdoc
30
README.rdoc
|
@ -1,10 +1,10 @@
|
|||
= webcat
|
||||
= capybara
|
||||
|
||||
* http://github.com/jnicklas/webcat
|
||||
* http://github.com/jnicklas/capybara
|
||||
|
||||
== Description:
|
||||
|
||||
Webcat is a unified API for writing web application integration tests for Rack
|
||||
Capybara is a unified API for writing web application integration tests for Rack
|
||||
applications. It works with any rack application and currently has support for
|
||||
Culerity, Selenium and rack-test.
|
||||
|
||||
|
@ -16,22 +16,22 @@ Clone and install from github for now
|
|||
|
||||
You can initialize a session and start issuing commands:
|
||||
|
||||
require 'webcat'
|
||||
require 'capybara'
|
||||
|
||||
session = Webcat::Session.new(:culerity, my_rack_app)
|
||||
session = Capybara::Session.new(:culerity, my_rack_app)
|
||||
session.within("//form[@id='session']") do
|
||||
session.fill_in 'Login', :with => 'user@example.com'
|
||||
session.fill_in 'Password', :with => 'password'
|
||||
end
|
||||
session.click_link 'Sign in'
|
||||
|
||||
Webcat provides a terser DSL:
|
||||
Capybara provides a terser DSL:
|
||||
|
||||
require 'webcat'
|
||||
require 'webcat/dsl'
|
||||
require 'capybara'
|
||||
require 'capybara/dsl'
|
||||
|
||||
include Webcat
|
||||
Webcat.default_driver = :culerity
|
||||
include Capybara
|
||||
Capybara.default_driver = :culerity
|
||||
|
||||
within("//form[@id='session']") do
|
||||
fill_in 'Login', :with => 'user@example.com'
|
||||
|
@ -41,8 +41,8 @@ Webcat provides a terser DSL:
|
|||
|
||||
If you want to use it with Cucumber, just require:
|
||||
|
||||
require 'webcat/cucumber'
|
||||
Webcat.app = my_rack_app
|
||||
require 'capybara/cucumber'
|
||||
Capybara.app = my_rack_app
|
||||
|
||||
Then write your steps like this:
|
||||
|
||||
|
@ -56,12 +56,12 @@ Then write your steps like this:
|
|||
|
||||
If you're using Rails, webcan can set up the rack app for you. Just do:
|
||||
|
||||
require 'webcat/cucumber'
|
||||
require 'webcat/rails'
|
||||
require 'capybara/cucumber'
|
||||
require 'capybara/rails'
|
||||
|
||||
== Gotchas:
|
||||
|
||||
* Everything is *case sensitive*. Webcat heavily relies on XPath, which doesn't
|
||||
* Everything is *case sensitive*. Capybara heavily relies on XPath, which doesn't
|
||||
support case insensitive searches.
|
||||
* Unchecking checkboxes and filling in password fields is currently broken
|
||||
under Culerity.
|
||||
|
|
4
Rakefile
4
Rakefile
|
@ -2,7 +2,7 @@ require 'rubygems'
|
|||
gem 'hoe', '>= 2.1.0'
|
||||
require 'hoe'
|
||||
require 'fileutils'
|
||||
require './lib/webcat'
|
||||
require './lib/capybara'
|
||||
|
||||
Hoe.plugin :newgem
|
||||
# Hoe.plugin :website
|
||||
|
@ -10,7 +10,7 @@ Hoe.plugin :newgem
|
|||
|
||||
# Generate all the Rake tasks
|
||||
# Run 'rake -T' to see list of generated tasks (from gem root directory)
|
||||
$hoe = Hoe.spec 'webcat' do
|
||||
$hoe = Hoe.spec 'capybara' do
|
||||
self.developer 'Jonas Nicklas', 'jonas.nicklas@gmail.com'
|
||||
self.rubyforge_name = self.name # TODO this is default value
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
session = Webcat::Session.new('http://localhost:3000')
|
||||
session = Capybara::Session.new('http://localhost:3000')
|
||||
|
||||
session.visit '/'
|
||||
|
||||
|
|
29
lib/capybara.rb
Normal file
29
lib/capybara.rb
Normal file
|
@ -0,0 +1,29 @@
|
|||
require 'nokogiri'
|
||||
|
||||
module Capybara
|
||||
VERSION = '0.1'
|
||||
|
||||
class CapybaraError < StandardError; end
|
||||
class DriverNotFoundError < CapybaraError; end
|
||||
class ElementNotFound < CapybaraError; end
|
||||
|
||||
class << self
|
||||
attr_accessor :debug, :asset_root
|
||||
|
||||
def log(message)
|
||||
puts "[capybara] #{message}" if debug
|
||||
true
|
||||
end
|
||||
end
|
||||
|
||||
autoload :Server, 'capybara/server'
|
||||
autoload :Session, 'capybara/session'
|
||||
|
||||
module Driver
|
||||
autoload :RackTest, 'capybara/driver/rack_test_driver'
|
||||
autoload :Culerity, 'capybara/driver/culerity_driver'
|
||||
autoload :SafariWatir, 'capybara/driver/safariwatir_driver'
|
||||
autoload :FireWatir, 'capybara/driver/firewatir_driver'
|
||||
autoload :Selenium, 'capybara/driver/selenium_driver'
|
||||
end
|
||||
end
|
|
@ -1,10 +1,10 @@
|
|||
require 'webcat'
|
||||
require 'webcat/dsl'
|
||||
require 'capybara'
|
||||
require 'capybara/dsl'
|
||||
|
||||
World(Webcat)
|
||||
World(Capybara)
|
||||
|
||||
After do
|
||||
Webcat.reset_sessions!
|
||||
Capybara.reset_sessions!
|
||||
end
|
||||
|
||||
require 'database_cleaner'
|
||||
|
@ -12,9 +12,9 @@ require 'database_cleaner/cucumber'
|
|||
DatabaseCleaner.strategy = :truncation
|
||||
|
||||
Before('@javascript') do
|
||||
Webcat.current_driver = Webcat.javascript_driver
|
||||
Capybara.current_driver = Capybara.javascript_driver
|
||||
end
|
||||
|
||||
After('@javascript') do
|
||||
Webcat.use_default_driver
|
||||
Capybara.use_default_driver
|
||||
end
|
|
@ -1,6 +1,6 @@
|
|||
require 'culerity'
|
||||
|
||||
class Webcat::Driver::Culerity
|
||||
class Capybara::Driver::Culerity
|
||||
class Node < Struct.new(:node)
|
||||
def text
|
||||
node.text
|
||||
|
@ -48,7 +48,7 @@ class Webcat::Driver::Culerity
|
|||
|
||||
def initialize(app)
|
||||
@app = app
|
||||
@rack_server = Webcat::Server.new(@app)
|
||||
@rack_server = Capybara::Server.new(@app)
|
||||
@rack_server.boot
|
||||
end
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
require 'watir'
|
||||
Watir::Browser.default = "firefox"
|
||||
|
||||
class Webcat::Driver::FireWatir
|
||||
class Capybara::Driver::FireWatir
|
||||
class Node < Struct.new(:node)
|
||||
def text
|
||||
node.text
|
||||
|
@ -31,7 +31,7 @@ class Webcat::Driver::FireWatir
|
|||
|
||||
def initialize(app)
|
||||
@app = app
|
||||
@rack_server = Webcat::Server.new(@app)
|
||||
@rack_server = Capybara::Server.new(@app)
|
||||
@rack_server.boot
|
||||
end
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
require 'rack/test'
|
||||
require 'nokogiri'
|
||||
|
||||
class Webcat::Driver::RackTest
|
||||
class Capybara::Driver::RackTest
|
||||
class Node < Struct.new(:session, :node)
|
||||
def text
|
||||
node.text
|
|
@ -1,6 +1,6 @@
|
|||
require 'safariwatir'
|
||||
|
||||
class Webcat::Driver::SafariWatir
|
||||
class Capybara::Driver::SafariWatir
|
||||
class Node < Struct.new(:node)
|
||||
def text
|
||||
node.text
|
||||
|
@ -30,7 +30,7 @@ class Webcat::Driver::SafariWatir
|
|||
|
||||
def initialize(app)
|
||||
@app = app
|
||||
@rack_server = Webcat::Server.new(@app)
|
||||
@rack_server = Capybara::Server.new(@app)
|
||||
@rack_server.boot
|
||||
end
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
require 'selenium-webdriver'
|
||||
|
||||
class Webcat::Driver::Selenium
|
||||
class Capybara::Driver::Selenium
|
||||
class Node < Struct.new(:node)
|
||||
def text
|
||||
node.text
|
||||
|
@ -64,7 +64,7 @@ class Webcat::Driver::Selenium
|
|||
|
||||
def initialize(app)
|
||||
@app = app
|
||||
@rack_server = Webcat::Server.new(@app)
|
||||
@rack_server = Capybara::Server.new(@app)
|
||||
@rack_server.boot
|
||||
end
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
module Webcat
|
||||
module Capybara
|
||||
class << self
|
||||
attr_writer :default_driver, :current_driver, :javascript_driver
|
||||
|
||||
|
@ -22,7 +22,7 @@ module Webcat
|
|||
end
|
||||
|
||||
def current_session
|
||||
session_pool["#{current_driver}#{app.object_id}"] ||= Webcat::Session.new(current_driver, app)
|
||||
session_pool["#{current_driver}#{app.object_id}"] ||= Capybara::Session.new(current_driver, app)
|
||||
end
|
||||
|
||||
def reset_sessions!
|
||||
|
@ -39,7 +39,7 @@ module Webcat
|
|||
extend(self)
|
||||
|
||||
def page
|
||||
Webcat.current_session
|
||||
Capybara.current_session
|
||||
end
|
||||
|
||||
SESSION_METHODS = [
|
11
lib/capybara/rails.rb
Normal file
11
lib/capybara/rails.rb
Normal file
|
@ -0,0 +1,11 @@
|
|||
require 'capybara'
|
||||
require 'capybara/dsl'
|
||||
|
||||
Capybara.app = Rack::Builder.new do
|
||||
map "/" do
|
||||
use Rails::Rack::Static
|
||||
run ActionController::Dispatcher.new
|
||||
end
|
||||
end.to_app
|
||||
|
||||
Capybara.asset_root = Rails.root.join('public')
|
|
@ -1,10 +1,10 @@
|
|||
module Webcat
|
||||
module Capybara
|
||||
module SaveAndOpenPage
|
||||
extend(self)
|
||||
|
||||
def save_and_open_page(html)
|
||||
require 'tempfile'
|
||||
tempfile = Tempfile.new("webcat#{rand(1000000)}")
|
||||
tempfile = Tempfile.new("capybara#{rand(1000000)}")
|
||||
tempfile.write(rewrite_css_and_image_references(html))
|
||||
tempfile.close
|
||||
open_in_browser(tempfile.path)
|
||||
|
@ -18,8 +18,8 @@ module Webcat
|
|||
end
|
||||
|
||||
def rewrite_css_and_image_references(response_html) # :nodoc:
|
||||
return response_html unless Webcat.asset_root
|
||||
response_html.gsub(/("|')\/(stylesheets|images)/, '\1' + Webcat.asset_root + '/\2')
|
||||
return response_html unless Capybara.asset_root
|
||||
response_html.gsub(/("|')\/(stylesheets|images)/, '\1' + Capybara.asset_root + '/\2')
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,7 +1,7 @@
|
|||
require 'net/http'
|
||||
require 'rack'
|
||||
|
||||
class Webcat::Server
|
||||
class Capybara::Server
|
||||
attr_reader :app
|
||||
|
||||
def initialize(app)
|
||||
|
@ -21,21 +21,21 @@ class Webcat::Server
|
|||
end
|
||||
|
||||
def boot
|
||||
Webcat.log "application has already booted" and return if responsive?
|
||||
Webcat.log "booting Rack applicartion on port #{port}"
|
||||
Capybara.log "application has already booted" and return if responsive?
|
||||
Capybara.log "booting Rack applicartion on port #{port}"
|
||||
start_time = Time.now
|
||||
Thread.new do
|
||||
Rack::Handler::Mongrel.run @app, :Port => port
|
||||
end
|
||||
Webcat.log "checking if application has booted"
|
||||
Capybara.log "checking if application has booted"
|
||||
loop do
|
||||
Webcat.log("application has booted") and break if responsive?
|
||||
Capybara.log("application has booted") and break if responsive?
|
||||
if Time.now - start_time > 10
|
||||
Webcat.log "Rack application timed out during boot"
|
||||
Capybara.log "Rack application timed out during boot"
|
||||
exit
|
||||
end
|
||||
|
||||
Webcat.log '.'
|
||||
Capybara.log '.'
|
||||
sleep 1
|
||||
end
|
||||
end
|
|
@ -1,4 +1,4 @@
|
|||
class Webcat::Session
|
||||
class Capybara::Session
|
||||
attr_reader :mode, :app
|
||||
|
||||
def initialize(mode, app)
|
||||
|
@ -9,13 +9,13 @@ class Webcat::Session
|
|||
def driver
|
||||
@driver ||= case mode
|
||||
when :rack_test
|
||||
Webcat::Driver::RackTest.new(app)
|
||||
Capybara::Driver::RackTest.new(app)
|
||||
when :culerity
|
||||
Webcat::Driver::Culerity.new(app)
|
||||
Capybara::Driver::Culerity.new(app)
|
||||
when :selenium
|
||||
Webcat::Driver::Selenium.new(app)
|
||||
Capybara::Driver::Selenium.new(app)
|
||||
else
|
||||
raise Webcat::DriverNotFoundError, "no driver called #{mode} was found"
|
||||
raise Capybara::DriverNotFoundError, "no driver called #{mode} was found"
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -82,15 +82,15 @@ class Webcat::Session
|
|||
def within(kind, scope=nil)
|
||||
kind, scope = :xpath, kind unless scope
|
||||
scope = css_to_xpath(scope) if kind == :css
|
||||
raise Webcat::ElementNotFound, "scope '#{scope}' not found on page" if find(scope).empty?
|
||||
raise Capybara::ElementNotFound, "scope '#{scope}' not found on page" if find(scope).empty?
|
||||
scopes.push(scope)
|
||||
yield
|
||||
scopes.pop
|
||||
end
|
||||
|
||||
def save_and_open_page
|
||||
require 'webcat/save_and_open_page'
|
||||
Webcat::SaveAndOpenPage.save_and_open_page(body)
|
||||
require 'capybara/save_and_open_page'
|
||||
Capybara::SaveAndOpenPage.save_and_open_page(body)
|
||||
end
|
||||
|
||||
private
|
||||
|
@ -120,7 +120,7 @@ private
|
|||
|
||||
def find_link(locator)
|
||||
link = find_element("//a[@id='#{locator}']", "//a[contains(.,'#{locator}')]", "//a[@title='#{locator}']")
|
||||
raise Webcat::ElementNotFound, "no link with title, id or text '#{locator}' found" unless link
|
||||
raise Capybara::ElementNotFound, "no link with title, id or text '#{locator}' found" unless link
|
||||
link
|
||||
end
|
||||
|
||||
|
@ -131,13 +131,13 @@ private
|
|||
"//input[@type='image'][@id='#{locator}']",
|
||||
"//input[@type='image'][@value='#{locator}']"
|
||||
)
|
||||
raise Webcat::ElementNotFound, "no button with value or id '#{locator}' found" unless button
|
||||
raise Capybara::ElementNotFound, "no button with value or id '#{locator}' found" unless button
|
||||
button
|
||||
end
|
||||
|
||||
def find_field(locator, *kinds)
|
||||
field = find_field_by_id(locator, *kinds) || find_field_by_label(locator, *kinds)
|
||||
raise Webcat::ElementNotFound, "no field of kind #{kinds.inspect} with id or'#{locator}' found" unless field
|
||||
raise Capybara::ElementNotFound, "no field of kind #{kinds.inspect} with id or'#{locator}' found" unless field
|
||||
field
|
||||
end
|
||||
|
|
@ -1,29 +0,0 @@
|
|||
require 'nokogiri'
|
||||
|
||||
module Webcat
|
||||
VERSION = '0.1'
|
||||
|
||||
class WebcatError < StandardError; end
|
||||
class DriverNotFoundError < WebcatError; end
|
||||
class ElementNotFound < WebcatError; end
|
||||
|
||||
class << self
|
||||
attr_accessor :debug, :asset_root
|
||||
|
||||
def log(message)
|
||||
puts "[webcat] #{message}" if debug
|
||||
true
|
||||
end
|
||||
end
|
||||
|
||||
autoload :Server, 'webcat/server'
|
||||
autoload :Session, 'webcat/session'
|
||||
|
||||
module Driver
|
||||
autoload :RackTest, 'webcat/driver/rack_test_driver'
|
||||
autoload :Culerity, 'webcat/driver/culerity_driver'
|
||||
autoload :SafariWatir, 'webcat/driver/safariwatir_driver'
|
||||
autoload :FireWatir, 'webcat/driver/firewatir_driver'
|
||||
autoload :Selenium, 'webcat/driver/selenium_driver'
|
||||
end
|
||||
end
|
|
@ -1,11 +0,0 @@
|
|||
require 'webcat'
|
||||
require 'webcat/dsl'
|
||||
|
||||
Webcat.app = Rack::Builder.new do
|
||||
map "/" do
|
||||
use Rails::Rack::Static
|
||||
run ActionController::Dispatcher.new
|
||||
end
|
||||
end.to_app
|
||||
|
||||
Webcat.asset_root = Rails.root.join('public')
|
|
@ -5,6 +5,6 @@ irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
|
|||
libs = " -r irb/completion"
|
||||
# Perhaps use a console_lib to store any extra methods I may want available in the cosole
|
||||
# libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
|
||||
libs << " -r #{File.dirname(__FILE__) + '/../lib/webcat.rb'}"
|
||||
puts "Loading webcat gem"
|
||||
libs << " -r #{File.dirname(__FILE__) + '/../lib/capybara.rb'}"
|
||||
puts "Loading capybara gem"
|
||||
exec "#{irb} #{libs} --simple-prompt"
|
|
@ -1,8 +1,8 @@
|
|||
require File.expand_path('../spec_helper', File.dirname(__FILE__))
|
||||
|
||||
describe Webcat::Driver::Culerity do
|
||||
describe Capybara::Driver::Culerity do
|
||||
before do
|
||||
@driver = Webcat::Driver::Culerity.new(TestApp)
|
||||
@driver = Capybara::Driver::Culerity.new(TestApp)
|
||||
end
|
||||
|
||||
it_should_behave_like "driver"
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
require File.expand_path('../spec_helper', File.dirname(__FILE__))
|
||||
|
||||
describe Webcat::Driver::FireWatir do
|
||||
describe Capybara::Driver::FireWatir do
|
||||
before do
|
||||
@driver = Webcat::Driver::FireWatir.new(TestApp)
|
||||
@driver = Capybara::Driver::FireWatir.new(TestApp)
|
||||
end
|
||||
|
||||
# it_should_behave_like "driver"
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
require File.expand_path('../spec_helper', File.dirname(__FILE__))
|
||||
|
||||
describe Webcat::Driver::RackTest do
|
||||
describe Capybara::Driver::RackTest do
|
||||
before do
|
||||
@driver = Webcat::Driver::RackTest.new(TestApp)
|
||||
@driver = Capybara::Driver::RackTest.new(TestApp)
|
||||
end
|
||||
|
||||
it_should_behave_like "driver"
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
require File.expand_path('../spec_helper', File.dirname(__FILE__))
|
||||
|
||||
describe Webcat::Driver::SafariWatir do
|
||||
describe Capybara::Driver::SafariWatir do
|
||||
before do
|
||||
@driver = Webcat::Driver::SafariWatir.new(TestApp)
|
||||
@driver = Capybara::Driver::SafariWatir.new(TestApp)
|
||||
end
|
||||
|
||||
# it_should_behave_like "driver"
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
require File.expand_path('../spec_helper', File.dirname(__FILE__))
|
||||
|
||||
describe Webcat::Driver::Selenium do
|
||||
describe Capybara::Driver::Selenium do
|
||||
before do
|
||||
@driver = Webcat::Driver::Selenium.new(TestApp)
|
||||
@driver = Capybara::Driver::Selenium.new(TestApp)
|
||||
end
|
||||
|
||||
it_should_behave_like "driver"
|
||||
|
|
|
@ -1,123 +1,123 @@
|
|||
require File.expand_path('spec_helper', File.dirname(__FILE__))
|
||||
|
||||
require 'webcat/dsl'
|
||||
require 'capybara/dsl'
|
||||
|
||||
describe Webcat do
|
||||
describe Capybara do
|
||||
|
||||
before do
|
||||
Webcat.app = TestApp
|
||||
Capybara.app = TestApp
|
||||
end
|
||||
|
||||
after do
|
||||
Webcat.default_driver = nil
|
||||
Webcat.use_default_driver
|
||||
Capybara.default_driver = nil
|
||||
Capybara.use_default_driver
|
||||
end
|
||||
|
||||
describe '#default_driver' do
|
||||
it "should default to rack_test" do
|
||||
Webcat.default_driver.should == :rack_test
|
||||
Capybara.default_driver.should == :rack_test
|
||||
end
|
||||
|
||||
it "should be changeable" do
|
||||
Webcat.default_driver = :culerity
|
||||
Webcat.default_driver.should == :culerity
|
||||
Capybara.default_driver = :culerity
|
||||
Capybara.default_driver.should == :culerity
|
||||
end
|
||||
end
|
||||
|
||||
describe '#current_driver' do
|
||||
it "should default to the default driver" do
|
||||
Webcat.current_driver.should == :rack_test
|
||||
Webcat.default_driver = :culerity
|
||||
Webcat.current_driver.should == :culerity
|
||||
Capybara.current_driver.should == :rack_test
|
||||
Capybara.default_driver = :culerity
|
||||
Capybara.current_driver.should == :culerity
|
||||
end
|
||||
|
||||
it "should be changeable" do
|
||||
Webcat.current_driver = :culerity
|
||||
Webcat.current_driver.should == :culerity
|
||||
Capybara.current_driver = :culerity
|
||||
Capybara.current_driver.should == :culerity
|
||||
end
|
||||
end
|
||||
|
||||
describe '#javascript_driver' do
|
||||
it "should default to selenium" do
|
||||
Webcat.javascript_driver.should == :selenium
|
||||
Capybara.javascript_driver.should == :selenium
|
||||
end
|
||||
|
||||
it "should be changeable" do
|
||||
Webcat.javascript_driver = :culerity
|
||||
Webcat.javascript_driver.should == :culerity
|
||||
Capybara.javascript_driver = :culerity
|
||||
Capybara.javascript_driver.should == :culerity
|
||||
end
|
||||
end
|
||||
|
||||
describe '#use_default_driver' do
|
||||
it "should restore the default driver" do
|
||||
Webcat.current_driver = :culerity
|
||||
Webcat.use_default_driver
|
||||
Webcat.current_driver.should == :rack_test
|
||||
Capybara.current_driver = :culerity
|
||||
Capybara.use_default_driver
|
||||
Capybara.current_driver.should == :rack_test
|
||||
end
|
||||
end
|
||||
|
||||
describe '#app' do
|
||||
it "should be changeable" do
|
||||
Webcat.app = "foobar"
|
||||
Webcat.app.should == 'foobar'
|
||||
Capybara.app = "foobar"
|
||||
Capybara.app.should == 'foobar'
|
||||
end
|
||||
end
|
||||
|
||||
describe '#current_session' do
|
||||
it "should choose a session object of the current driver type" do
|
||||
Webcat.current_session.should be_a(Webcat::Session)
|
||||
Capybara.current_session.should be_a(Capybara::Session)
|
||||
end
|
||||
|
||||
it "should use #app as the application" do
|
||||
Webcat.app = proc {}
|
||||
Webcat.current_session.app.should == Webcat.app
|
||||
Capybara.app = proc {}
|
||||
Capybara.current_session.app.should == Capybara.app
|
||||
end
|
||||
|
||||
it "should change with the current driver" do
|
||||
Webcat.current_session.mode.should == :rack_test
|
||||
Webcat.current_driver = :culerity
|
||||
Webcat.current_session.mode.should == :culerity
|
||||
Capybara.current_session.mode.should == :rack_test
|
||||
Capybara.current_driver = :culerity
|
||||
Capybara.current_session.mode.should == :culerity
|
||||
end
|
||||
|
||||
it "should be persistent even across driver changes" do
|
||||
object_id = Webcat.current_session.object_id
|
||||
Webcat.current_session.object_id.should == object_id
|
||||
Webcat.current_driver = :culerity
|
||||
Webcat.current_session.mode.should == :culerity
|
||||
Webcat.current_session.object_id.should_not == object_id
|
||||
object_id = Capybara.current_session.object_id
|
||||
Capybara.current_session.object_id.should == object_id
|
||||
Capybara.current_driver = :culerity
|
||||
Capybara.current_session.mode.should == :culerity
|
||||
Capybara.current_session.object_id.should_not == object_id
|
||||
|
||||
Webcat.current_driver = :rack_test
|
||||
Webcat.current_session.object_id.should == object_id
|
||||
Capybara.current_driver = :rack_test
|
||||
Capybara.current_session.object_id.should == object_id
|
||||
end
|
||||
|
||||
it "should change when changing application" do
|
||||
object_id = Webcat.current_session.object_id
|
||||
Webcat.current_session.object_id.should == object_id
|
||||
Webcat.app = proc {}
|
||||
Webcat.current_session.object_id.should_not == object_id
|
||||
Webcat.current_session.app.should == Webcat.app
|
||||
object_id = Capybara.current_session.object_id
|
||||
Capybara.current_session.object_id.should == object_id
|
||||
Capybara.app = proc {}
|
||||
Capybara.current_session.object_id.should_not == object_id
|
||||
Capybara.current_session.app.should == Capybara.app
|
||||
end
|
||||
end
|
||||
|
||||
describe '.reset_sessions!' do
|
||||
it "should clear any persisted sessions" do
|
||||
object_id = Webcat.current_session.object_id
|
||||
Webcat.current_session.object_id.should == object_id
|
||||
Webcat.reset_sessions!
|
||||
Webcat.current_session.object_id.should_not == object_id
|
||||
object_id = Capybara.current_session.object_id
|
||||
Capybara.current_session.object_id.should == object_id
|
||||
Capybara.reset_sessions!
|
||||
Capybara.current_session.object_id.should_not == object_id
|
||||
end
|
||||
end
|
||||
|
||||
describe 'the DSL' do
|
||||
before do
|
||||
@session = Webcat
|
||||
@session = Capybara
|
||||
end
|
||||
|
||||
it_should_behave_like "session"
|
||||
|
||||
it "should be possible to include it in another class" do
|
||||
klass = Class.new do
|
||||
include Webcat
|
||||
include Capybara
|
||||
end
|
||||
foo = klass.new
|
||||
foo.visit('/with_html')
|
||||
|
@ -127,7 +127,7 @@ describe Webcat do
|
|||
|
||||
it "should provide a 'page' shortcut for more expressive tests" do
|
||||
klass = Class.new do
|
||||
include Webcat
|
||||
include Capybara
|
||||
end
|
||||
foo = klass.new
|
||||
foo.page.visit('/with_html')
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
require File.expand_path('../spec_helper', File.dirname(__FILE__))
|
||||
|
||||
describe Webcat::Session do
|
||||
describe Capybara::Session do
|
||||
context 'with culerity driver' do
|
||||
before do
|
||||
@session = Webcat::Session.new(:culerity, TestApp)
|
||||
@session = Capybara::Session.new(:culerity, TestApp)
|
||||
end
|
||||
|
||||
describe '#driver' do
|
||||
it "should be a rack test driver" do
|
||||
@session.driver.should be_an_instance_of(Webcat::Driver::Culerity)
|
||||
@session.driver.should be_an_instance_of(Capybara::Driver::Culerity)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
require File.expand_path('../spec_helper', File.dirname(__FILE__))
|
||||
|
||||
describe Webcat::Session do
|
||||
describe Capybara::Session do
|
||||
context 'with rack test driver' do
|
||||
before do
|
||||
@session = Webcat::Session.new(:rack_test, TestApp)
|
||||
@session = Capybara::Session.new(:rack_test, TestApp)
|
||||
end
|
||||
|
||||
describe '#driver' do
|
||||
it "should be a rack test driver" do
|
||||
@session.driver.should be_an_instance_of(Webcat::Driver::RackTest)
|
||||
@session.driver.should be_an_instance_of(Capybara::Driver::RackTest)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
require File.expand_path('../spec_helper', File.dirname(__FILE__))
|
||||
|
||||
describe Webcat::Session do
|
||||
describe Capybara::Session do
|
||||
context 'with selenium driver' do
|
||||
before do
|
||||
@session = Webcat::Session.new(:selenium, TestApp)
|
||||
@session = Capybara::Session.new(:selenium, TestApp)
|
||||
end
|
||||
|
||||
describe '#driver' do
|
||||
it "should be a rack test driver" do
|
||||
@session.driver.should be_an_instance_of(Webcat::Driver::Selenium)
|
||||
@session.driver.should be_an_instance_of(Capybara::Driver::Selenium)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -52,7 +52,7 @@ shared_examples_for "session" do
|
|||
it "should raise an error" do
|
||||
running do
|
||||
@session.click_link('does not exist')
|
||||
end.should raise_error(Webcat::ElementNotFound)
|
||||
end.should raise_error(Capybara::ElementNotFound)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -149,7 +149,7 @@ shared_examples_for "session" do
|
|||
it "should raise an error" do
|
||||
running do
|
||||
@session.click_button('does not exist')
|
||||
end.should raise_error(Webcat::ElementNotFound)
|
||||
end.should raise_error(Capybara::ElementNotFound)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -206,7 +206,7 @@ shared_examples_for "session" do
|
|||
it "should raise an error" do
|
||||
running do
|
||||
@session.fill_in('does not exist', :with => 'Blah blah')
|
||||
end.should raise_error(Webcat::ElementNotFound)
|
||||
end.should raise_error(Capybara::ElementNotFound)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -505,7 +505,7 @@ shared_examples_for "session" do
|
|||
running {
|
||||
@session.within("//div[@id='doesnotexist']") do
|
||||
end
|
||||
}.should raise_error(Webcat::ElementNotFound)
|
||||
}.should raise_error(Capybara::ElementNotFound)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -526,12 +526,12 @@ shared_examples_for "session" do
|
|||
end
|
||||
end
|
||||
|
||||
describe Webcat::Session do
|
||||
describe Capybara::Session do
|
||||
context 'with non-existant driver' do
|
||||
it "should raise an error" do
|
||||
running {
|
||||
Webcat::Session.new(:quox, TestApp).driver
|
||||
}.should raise_error(Webcat::DriverNotFoundError)
|
||||
Capybara::Session.new(:quox, TestApp).driver
|
||||
}.should raise_error(Capybara::DriverNotFoundError)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,7 +2,7 @@ $:.unshift(File.expand_path('../lib', File.dirname(__FILE__)))
|
|||
$:.unshift(File.dirname(__FILE__))
|
||||
|
||||
require 'rubygems'
|
||||
require 'webcat'
|
||||
require 'capybara'
|
||||
require 'test_app'
|
||||
require 'drivers_spec'
|
||||
require 'session_spec'
|
||||
|
|
Loading…
Add table
Reference in a new issue