Move adapters to webrat/adapters, and Rails and Merb integration code into webrat/integrations

This commit is contained in:
Bryan Helmkamp 2009-08-19 23:30:06 -04:00
parent 610f0fc217
commit 2fc9f3f7f9
16 changed files with 48 additions and 68 deletions

View File

@ -2,6 +2,12 @@ require "rack"
require "nokogiri" require "nokogiri"
module Webrat module Webrat
autoload :MechanizeAdapter, "webrat/adapters/mechanize"
autoload :MerbAdapter, "webrat/adapters/merb"
autoload :RackAdapter, "webrat/adapters/rack"
autoload :RailsAdapter, "webrat/adapters/rails"
autoload :SinatraAdapter, "webrat/adapters/sinatra"
# The common base class for all exceptions raised by Webrat. # The common base class for all exceptions raised by Webrat.
class WebratError < StandardError class WebratError < StandardError
end end

View File

@ -0,0 +1,11 @@
require "webrat/integrations/merb"
module Webrat
class MerbAdapter < RackAdapter #:nodoc:
def initialize(context=nil)
app = context.respond_to?(:app) ?
context.app : Merb::Rack::Application.new
super(Rack::Test::Session.new(Rack::MockSession.new(app, "www.example.com")))
end
end
end

View File

@ -1,7 +1,4 @@
require "webrat" require "webrat/integrations/rails"
require "action_controller"
require "action_controller/integration"
require "action_controller/record_identifier" require "action_controller/record_identifier"
module Webrat module Webrat
@ -96,11 +93,4 @@ module Webrat
integration_session.response integration_session.response
end end
end end
end end
module ActionController #:nodoc:
IntegrationTest.class_eval do
include Webrat::Methods
include Webrat::Matchers
end
end

View File

@ -1,5 +1,3 @@
require "webrat/rack"
module Webrat module Webrat
class SinatraAdapter < RackAdapter class SinatraAdapter < RackAdapter
def initialize(context) def initialize(context)

View File

@ -79,13 +79,11 @@ module Webrat
def mode=(mode) def mode=(mode)
@mode = mode.to_sym @mode = mode.to_sym
# This is a temporary hack to support backwards compatibility begin
# with Merb 1.0.8 until it's updated to use the new Webrat.configure require("webrat/integrations/#{mode}")
# syntax rescue LoadError
if @mode == :merb # Only some modes have integration code that needs to
require("webrat/merb_adapter") # be loaded, so this is OK
else
require("webrat/#{mode}")
end end
end end

View File

@ -11,7 +11,7 @@ module Webrat
when :rails when :rails
defined?(RAILS_DEFAULT_LOGGER) ? RAILS_DEFAULT_LOGGER : nil defined?(RAILS_DEFAULT_LOGGER) ? RAILS_DEFAULT_LOGGER : nil
when :merb when :merb
Merb.logger ::Merb.logger
else else
@logger ||= begin @logger ||= begin
require "logger" require "logger"

View File

@ -0,0 +1,10 @@
module Merb #:nodoc:
module Test #:nodoc:
module RequestHelper #:nodoc:
def request(uri, env = {})
@_webrat_session ||= Webrat::MerbAdapter.new
@_webrat_session.response = @_webrat_session.request(uri, env)
end
end
end
end

View File

@ -0,0 +1,9 @@
require "action_controller"
require "action_controller/integration"
module ActionController #:nodoc:
IntegrationTest.class_eval do
include Webrat::Methods
include Webrat::Matchers
end
end

View File

@ -1,24 +0,0 @@
require "webrat"
require "merb-core"
require "webrat/rack"
module Webrat
class MerbAdapter < RackAdapter #:nodoc:
def initialize(context=nil)
app = context.respond_to?(:app) ?
context.app : Merb::Rack::Application.new
super(Rack::Test::Session.new(Rack::MockSession.new(app, "www.example.com")))
end
end
end
module Merb #:nodoc:
module Test #:nodoc:
module RequestHelper #:nodoc:
def request(uri, env = {})
@_webrat_session ||= Webrat::MerbAdapter.new
@_webrat_session.response = @_webrat_session.request(uri, env)
end
end
end
end

View File

@ -3,6 +3,8 @@ require "webrat/selenium/selenium_rc_server"
require "webrat/selenium/application_server_factory" require "webrat/selenium/application_server_factory"
require "webrat/selenium/application_servers/base" require "webrat/selenium/application_servers/base"
require "selenium"
module Webrat module Webrat
class TimeoutError < WebratError class TimeoutError < WebratError
end end

View File

@ -45,24 +45,6 @@ describe Webrat::Configuration do
config.selenium_server_port.should == 1234 config.selenium_server_port.should == 1234
end end
[:rails,
:selenium,
:rack,
:sinatra,
:mechanize].each do |mode|
it "should require correct lib when in #{mode} mode" do
config = Webrat::Configuration.new
config.should_receive(:require).with("webrat/#{mode}")
config.mode = mode
end
end
it "should require merb_adapter when in merb mode" do
config = Webrat::Configuration.new
config.should_receive(:require).with("webrat/merb_adapter")
config.mode = :merb
end
describe "Selenium" do describe "Selenium" do
before :each do before :each do
@config = Webrat::Configuration.new @config = Webrat::Configuration.new

View File

@ -1,7 +1,5 @@
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
require "webrat/mechanize"
describe Webrat::MechanizeAdapter do describe Webrat::MechanizeAdapter do
before :each do before :each do
Webrat.configuration.mode = :mechanize Webrat.configuration.mode = :mechanize

View File

@ -1,7 +1,5 @@
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
require "webrat/rails"
describe Webrat::RailsAdapter do describe Webrat::RailsAdapter do
before :each do before :each do
Webrat.configuration.mode = :rails Webrat.configuration.mode = :rails

View File

@ -47,6 +47,8 @@ Spec::Runner.configure do |config|
end end
end end
require "merb-core"
Webrat.configure do |config| Webrat.configure do |config|
config.mode = :merb config.mode = :merb
end end