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
class WebcatError < StandardError; end
class DriverNotFoundError < WebcatError; end
class << self
attr_accessor :debug

View File

@ -7,7 +7,14 @@ class Webcat::Session
end
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
def visit(path)
@ -15,6 +22,6 @@ class Webcat::Session
end
def body
driver.response.body
driver.body
end
end

View File

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

View File

@ -1,34 +1,68 @@
require File.expand_path('spec_helper', File.dirname(__FILE__))
describe Webcat::Session 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)
shared_examples_for "session" do
describe '#app' do
it "should remember the application" do
@session.app.should == TestApp
end
end
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
describe '#app' do
it "should remember the application" do
@session.app.should == TestApp
context 'with rack test driver' do
before do
@session = Webcat::Session.new(:rack_test, TestApp)
end
end
describe '#mode' do
it "should remember the mode" do
@session.mode.should == :rack_test
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
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'
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