1
0
Fork 0
mirror of https://github.com/teamcapybara/capybara.git synced 2022-11-09 12:08:07 -05:00

Get culerity driver into session

This commit is contained in:
Jonas Nicklas and Kevin Fitzpatrick 2009-11-04 23:17:17 +01:00 committed by Jonas Nicklas
parent f4cbc91da8
commit 0b379be094
4 changed files with 70 additions and 24 deletions

View file

@ -1,4 +1,7 @@
module Webcat module Webcat
class WebcatError < StandardError; end
class DriverNotFoundError < WebcatError; end
class << self class << self
attr_accessor :debug attr_accessor :debug

View file

@ -7,7 +7,14 @@ class Webcat::Session
end end
def driver def driver
@driver ||= Webcat::Driver::RackTest.new(app) @driver ||= case mode
when :rack_test
Webcat::Driver::RackTest.new(app)
when :culerity
Webcat::Driver::Culerity.new(app)
else
raise Webcat::DriverNotFoundError, "no driver called #{mode} was found"
end
end end
def visit(path) def visit(path)
@ -15,6 +22,6 @@ class Webcat::Session
end end
def body def body
driver.response.body driver.body
end end
end end

View file

@ -5,6 +5,8 @@ require 'webcat'
require 'sinatra/base' require 'sinatra/base'
require 'rack' require 'rack'
alias :running :lambda
class TestApp < Sinatra::Base class TestApp < Sinatra::Base
get '/' do get '/' do
'Hello world!' 'Hello world!'

View file

@ -1,28 +1,13 @@
require File.expand_path('spec_helper', File.dirname(__FILE__)) require File.expand_path('spec_helper', File.dirname(__FILE__))
describe Webcat::Session do describe Webcat::Session do
before do shared_examples_for "session" do
@session = Webcat::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)
end
end
describe '#app' do describe '#app' do
it "should remember the application" do it "should remember the application" do
@session.app.should == TestApp @session.app.should == TestApp
end end
end end
describe '#mode' do
it "should remember the mode" do
@session.mode.should == :rack_test
end
end
describe '#visit' do describe '#visit' do
it "should fetch a response from the driver" do it "should fetch a response from the driver" do
@session.visit('/') @session.visit('/')
@ -31,5 +16,54 @@ describe Webcat::Session do
@session.body.should == 'Another World' @session.body.should == 'Another World'
end end
end end
end
context 'with rack test driver' do
before do
@session = Webcat::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)
end
end
describe '#mode' do
it "should remember the mode" do
@session.mode.should == :rack_test
end
end
it_should_behave_like "session"
end
context 'with culerity driver' do
before do
@session = Webcat::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)
end
end
describe '#mode' do
it "should remember the mode" do
@session.mode.should == :culerity
end
end
it_should_behave_like "session"
end
context 'with non-existent driver' do
it "should raise an error" do
running {
Webcat::Session.new(:quox, TestApp).driver
}.should raise_error(Webcat::DriverNotFoundError)
end
end
end end