mirror of
https://github.com/teamcapybara/capybara.git
synced 2022-11-09 12:08:07 -05:00
Drivers are now manually registered
This commit is contained in:
parent
1f045d222c
commit
7fc12fd78e
3 changed files with 50 additions and 7 deletions
|
@ -45,6 +45,27 @@ module Capybara
|
|||
def configure
|
||||
yield self
|
||||
end
|
||||
|
||||
##
|
||||
#
|
||||
# Register a new driver for Capybara.
|
||||
#
|
||||
# Capybara.register_driver :rack_test do |app|
|
||||
# Capybara::Driver::RackTest.new(app)
|
||||
# end
|
||||
#
|
||||
# @param [Symbol] name The name of the new driver
|
||||
# @yield [app] This block takes a rack app and returns a Capybara driver
|
||||
# @yieldparam [<Rack>] app The rack application that this driver runs agains. May be nil.
|
||||
# @yieldreturn [Capybara::Driver::Base] A Capybara driver instance
|
||||
#
|
||||
def register_driver(name, &block)
|
||||
drivers[name] = block
|
||||
end
|
||||
|
||||
def drivers
|
||||
@drivers ||= {}
|
||||
end
|
||||
end
|
||||
|
||||
autoload :Server, 'capybara/server'
|
||||
|
@ -72,3 +93,14 @@ Capybara.configure do |config|
|
|||
config.ignore_hidden_elements = false
|
||||
end
|
||||
|
||||
Capybara.register_driver :rack_test do |app|
|
||||
Capybara::Driver::RackTest.new(app)
|
||||
end
|
||||
|
||||
Capybara.register_driver :culerity do |app|
|
||||
Capybara::Driver::Culerity.new(app)
|
||||
end
|
||||
|
||||
Capybara.register_driver :selenium do |app|
|
||||
Capybara::Driver::Selenium.new(app)
|
||||
end
|
||||
|
|
|
@ -43,12 +43,12 @@ module Capybara
|
|||
end
|
||||
|
||||
def driver
|
||||
@driver ||= begin
|
||||
string = mode.to_s
|
||||
string.gsub!(%r{(^.)|(_.)}) { |m| m[m.length-1,1].upcase }
|
||||
Capybara::Driver.const_get(string.to_sym).new(app)
|
||||
rescue NameError
|
||||
raise Capybara::DriverNotFoundError, "no driver called #{mode} was found"
|
||||
@driver ||= begin
|
||||
unless Capybara.drivers.has_key?(mode)
|
||||
other_drivers = Capybara.drivers.keys.map { |key| key.inspect }
|
||||
raise Capybara::DriverNotFoundError, "no driver called #{mode.inspect} was found, available drivers: #{other_drivers.join(', ')}"
|
||||
end
|
||||
Capybara.drivers[mode].call(app)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -14,5 +14,16 @@ describe Capybara do
|
|||
Capybara.default_wait_time.should == 5
|
||||
end
|
||||
end
|
||||
|
||||
describe '.register_driver' do
|
||||
it "should add a new driver" do
|
||||
Capybara.register_driver :schmoo do |app|
|
||||
Capybara::Driver::RackTest.new(app)
|
||||
end
|
||||
session = Capybara::Session.new(:schmoo, TestApp)
|
||||
session.visit('/')
|
||||
session.body.should include("Hello world!")
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue