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,34 +1,68 @@
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) describe '#app' do
end it "should remember the application" do
@session.app.should == TestApp
describe '#driver' do end
it "should be a rack test driver" do end
@session.driver.should be_an_instance_of(Webcat::Driver::RackTest)
describe '#visit' do
it "should fetch a response from the driver" do
@session.visit('/')
@session.body.should == 'Hello world!'
@session.visit('/foo')
@session.body.should == 'Another World'
end
end end
end end
describe '#app' do context 'with rack test driver' do
it "should remember the application" do before do
@session.app.should == TestApp @session = Webcat::Session.new(:rack_test, TestApp)
end end
end
describe '#driver' do
describe '#mode' do it "should be a rack test driver" do
it "should remember the mode" do @session.driver.should be_an_instance_of(Webcat::Driver::RackTest)
@session.mode.should == :rack_test end
end end
describe '#mode' do
it "should remember the mode" do
@session.mode.should == :rack_test
end
end
it_should_behave_like "session"
end end
describe '#visit' do context 'with culerity driver' do
it "should fetch a response from the driver" do before do
@session.visit('/') @session = Webcat::Session.new(:culerity, TestApp)
@session.body.should == 'Hello world!' end
@session.visit('/foo')
@session.body.should == 'Another World' 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