Cleanup the way the tests switch Webrat modes

This commit is contained in:
Bryan Helmkamp 2008-12-25 23:25:27 -05:00
parent 22c7834512
commit 0eaad52768
11 changed files with 41 additions and 59 deletions

View File

@ -1,4 +1,6 @@
require "webrat" require "webrat"
require "action_controller"
require "action_controller/integration" require "action_controller/integration"
module Webrat module Webrat

View File

@ -7,12 +7,21 @@ begin require "redgreen" unless ENV['TM_CURRENT_LINE']; rescue LoadError; end
webrat_path = File.expand_path(File.dirname(__FILE__) + "/../lib/") webrat_path = File.expand_path(File.dirname(__FILE__) + "/../lib/")
$LOAD_PATH.unshift(webrat_path) unless $LOAD_PATH.include?(webrat_path) $LOAD_PATH.unshift(webrat_path) unless $LOAD_PATH.include?(webrat_path)
require "merb-core"
require "webrat/merb"
require "webrat" require "webrat"
require File.expand_path(File.dirname(__FILE__) + "/fakes/test_session") require File.expand_path(File.dirname(__FILE__) + "/fakes/test_session")
module Webrat
@@previous_config = nil
def self.cache_config_for_test
@@previous_config = Webrat.configuration.clone
end
def self.reset_for_test
@@configuration = @@previous_config if @@previous_config
end
end
Spec::Runner.configure do |config| Spec::Runner.configure do |config|
include Webrat::Methods include Webrat::Methods
@ -26,22 +35,15 @@ Spec::Runner.configure do |config|
webrat_session.response_body = xml webrat_session.response_body = xml
end end
config.before :each do
Webrat.cache_config_for_test
end end
module Webrat config.after :each do
@@previous_config = nil Webrat.reset_for_test
end
def self.cache_config_for_test
@@previous_config = Webrat.configuration.clone
end end
def self.reset_for_test Webrat.configure do |config|
@@configuration = @@previous_config if @@previous_config config.mode = :merb
end
class Configuration
def mode_for_test= (mode)
@mode = mode
end
end
end end

View File

@ -4,14 +4,6 @@ describe Webrat::Configuration do
predicate_matchers[:parse_with_nokogiri] = :parse_with_nokogiri? predicate_matchers[:parse_with_nokogiri] = :parse_with_nokogiri?
predicate_matchers[:open_error_files] = :open_error_files? predicate_matchers[:open_error_files] = :open_error_files?
before do
Webrat.cache_config_for_test
end
after do
Webrat.reset_for_test
end
it "should have a mode" do it "should have a mode" do
Webrat.configuration.should respond_to(:mode) Webrat.configuration.should respond_to(:mode)
end end

View File

@ -87,12 +87,8 @@ describe Webrat::Session do
describe "#request_page" do describe "#request_page" do
before(:each) do before(:each) do
Webrat.cache_config_for_test
webrat_session = Webrat::Session.new webrat_session = Webrat::Session.new
end end
after(:each) do
Webrat.reset_for_test
end
it "should raise an error if the request is not a success" do it "should raise an error if the request is not a success" do
webrat_session.stub!(:get) webrat_session.stub!(:get)

View File

@ -1,13 +1,10 @@
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
describe "Webrat::MechanizeSession" do require "webrat/mechanize"
before :all do
Webrat.cache_config_for_test
Webrat.configuration.mode = :mechanize
end
after :all do describe Webrat::MechanizeSession do
Webrat.reset_for_test before :each do
Webrat.configuration.mode = :mechanize
end end
before(:each) do before(:each) do

View File

@ -1,2 +0,0 @@
require 'merb-core'
require "webrat/merb"

View File

@ -1,5 +1,4 @@
require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper") require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper")
require File.expand_path(File.dirname(__FILE__) + "/helper")
describe HashWithIndifferentAccess do describe HashWithIndifferentAccess do
it "should not update constructor when not a hash" do it "should not update constructor when not a hash" do

View File

@ -2,8 +2,7 @@ require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper")
require "webrat/merb" require "webrat/merb"
describe Webrat::Session do describe Webrat::MerbSession do
it "should not pass empty params if data is and empty hash" do it "should not pass empty params if data is and empty hash" do
session = Webrat::MerbSession.new session = Webrat::MerbSession.new
response = OpenStruct.new response = OpenStruct.new

View File

@ -1,7 +1,8 @@
require File.expand_path(File.dirname(__FILE__) + '/helper') require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
describe "attach_file" do describe "attach_file" do
before do before do
Webrat.configuration.mode = :rails
@filename = __FILE__ @filename = __FILE__
@uploaded_file = mock("uploaded file") @uploaded_file = mock("uploaded file")
ActionController::TestUploadedFile.stub!(:new => @uploaded_file) ActionController::TestUploadedFile.stub!(:new => @uploaded_file)

View File

@ -1,10 +0,0 @@
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
require "active_support"
silence_warnings do
require "action_controller"
require "action_controller/integration"
end
require "webrat/rails"
Webrat.configuration.mode_for_test = :rails

View File

@ -1,6 +1,12 @@
require File.expand_path(File.dirname(__FILE__) + '/helper') require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
require "webrat/rails"
describe Webrat::RailsSession do describe Webrat::RailsSession do
before do
Webrat.configuration.mode = :rails
end
it "should delegate response_body to the session response body" do it "should delegate response_body to the session response body" do
response = mock("response", :body => "<html>") response = mock("response", :body => "<html>")
integration_session = mock("integration session", :response => response) integration_session = mock("integration session", :response => response)