Cleanup the way the tests switch Webrat modes
This commit is contained in:
parent
22c7834512
commit
0eaad52768
@ -1,4 +1,6 @@
|
||||
require "webrat"
|
||||
|
||||
require "action_controller"
|
||||
require "action_controller/integration"
|
||||
|
||||
module Webrat
|
||||
|
@ -7,12 +7,21 @@ begin require "redgreen" unless ENV['TM_CURRENT_LINE']; rescue LoadError; end
|
||||
webrat_path = File.expand_path(File.dirname(__FILE__) + "/../lib/")
|
||||
$LOAD_PATH.unshift(webrat_path) unless $LOAD_PATH.include?(webrat_path)
|
||||
|
||||
require "merb-core"
|
||||
require "webrat/merb"
|
||||
|
||||
require "webrat"
|
||||
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|
|
||||
include Webrat::Methods
|
||||
|
||||
@ -26,22 +35,15 @@ Spec::Runner.configure do |config|
|
||||
webrat_session.response_body = xml
|
||||
end
|
||||
|
||||
config.before :each do
|
||||
Webrat.cache_config_for_test
|
||||
end
|
||||
|
||||
module Webrat
|
||||
@@previous_config = nil
|
||||
|
||||
def self.cache_config_for_test
|
||||
@@previous_config = Webrat.configuration.clone
|
||||
config.after :each do
|
||||
Webrat.reset_for_test
|
||||
end
|
||||
end
|
||||
|
||||
def self.reset_for_test
|
||||
@@configuration = @@previous_config if @@previous_config
|
||||
end
|
||||
|
||||
class Configuration
|
||||
def mode_for_test= (mode)
|
||||
@mode = mode
|
||||
end
|
||||
end
|
||||
Webrat.configure do |config|
|
||||
config.mode = :merb
|
||||
end
|
@ -4,14 +4,6 @@ describe Webrat::Configuration do
|
||||
predicate_matchers[:parse_with_nokogiri] = :parse_with_nokogiri?
|
||||
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
|
||||
Webrat.configuration.should respond_to(:mode)
|
||||
end
|
||||
|
@ -87,12 +87,8 @@ describe Webrat::Session do
|
||||
|
||||
describe "#request_page" do
|
||||
before(:each) do
|
||||
Webrat.cache_config_for_test
|
||||
webrat_session = Webrat::Session.new
|
||||
end
|
||||
after(:each) do
|
||||
Webrat.reset_for_test
|
||||
end
|
||||
|
||||
it "should raise an error if the request is not a success" do
|
||||
webrat_session.stub!(:get)
|
||||
|
@ -1,13 +1,10 @@
|
||||
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
||||
|
||||
describe "Webrat::MechanizeSession" do
|
||||
before :all do
|
||||
Webrat.cache_config_for_test
|
||||
Webrat.configuration.mode = :mechanize
|
||||
end
|
||||
require "webrat/mechanize"
|
||||
|
||||
after :all do
|
||||
Webrat.reset_for_test
|
||||
describe Webrat::MechanizeSession do
|
||||
before :each do
|
||||
Webrat.configuration.mode = :mechanize
|
||||
end
|
||||
|
||||
before(:each) do
|
||||
|
@ -1,2 +0,0 @@
|
||||
require 'merb-core'
|
||||
require "webrat/merb"
|
@ -1,5 +1,4 @@
|
||||
require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper")
|
||||
require File.expand_path(File.dirname(__FILE__) + "/helper")
|
||||
|
||||
describe HashWithIndifferentAccess do
|
||||
it "should not update constructor when not a hash" do
|
||||
|
@ -2,8 +2,7 @@ require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper")
|
||||
|
||||
require "webrat/merb"
|
||||
|
||||
describe Webrat::Session do
|
||||
|
||||
describe Webrat::MerbSession do
|
||||
it "should not pass empty params if data is and empty hash" do
|
||||
session = Webrat::MerbSession.new
|
||||
response = OpenStruct.new
|
@ -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
|
||||
before do
|
||||
Webrat.configuration.mode = :rails
|
||||
@filename = __FILE__
|
||||
@uploaded_file = mock("uploaded file")
|
||||
ActionController::TestUploadedFile.stub!(:new => @uploaded_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
|
@ -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
|
||||
before do
|
||||
Webrat.configuration.mode = :rails
|
||||
end
|
||||
|
||||
it "should delegate response_body to the session response body" do
|
||||
response = mock("response", :body => "<html>")
|
||||
integration_session = mock("integration session", :response => response)
|
||||
|
Loading…
Reference in New Issue
Block a user