From 0b379be0949551db358c1c668cfa634906f4aa5b Mon Sep 17 00:00:00 2001 From: Jonas Nicklas and Kevin Fitzpatrick Date: Wed, 4 Nov 2009 23:17:17 +0100 Subject: [PATCH] Get culerity driver into session --- lib/webcat.rb | 3 ++ lib/webcat/session.rb | 11 ++++-- spec/spec_helper.rb | 2 ++ spec/webcat_spec.rb | 78 +++++++++++++++++++++++++++++++------------ 4 files changed, 70 insertions(+), 24 deletions(-) diff --git a/lib/webcat.rb b/lib/webcat.rb index d4d7f2fc..d24fbd21 100644 --- a/lib/webcat.rb +++ b/lib/webcat.rb @@ -1,4 +1,7 @@ module Webcat + class WebcatError < StandardError; end + class DriverNotFoundError < WebcatError; end + class << self attr_accessor :debug diff --git a/lib/webcat/session.rb b/lib/webcat/session.rb index b3e4836c..5be3b166 100644 --- a/lib/webcat/session.rb +++ b/lib/webcat/session.rb @@ -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 \ No newline at end of file diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index e22c1633..e2c9ada2 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -5,6 +5,8 @@ require 'webcat' require 'sinatra/base' require 'rack' +alias :running :lambda + class TestApp < Sinatra::Base get '/' do 'Hello world!' diff --git a/spec/webcat_spec.rb b/spec/webcat_spec.rb index 8390e969..9e361e76 100644 --- a/spec/webcat_spec.rb +++ b/spec/webcat_spec.rb @@ -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