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"
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.
class WebratError < StandardError
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 "action_controller"
require "action_controller/integration"
require "webrat/integrations/rails"
require "action_controller/record_identifier"
module Webrat
@ -97,10 +94,3 @@ module Webrat
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
class SinatraAdapter < RackAdapter
def initialize(context)

View File

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

View File

@ -11,7 +11,7 @@ module Webrat
when :rails
defined?(RAILS_DEFAULT_LOGGER) ? RAILS_DEFAULT_LOGGER : nil
when :merb
Merb.logger
::Merb.logger
else
@logger ||= begin
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_servers/base"
require "selenium"
module Webrat
class TimeoutError < WebratError
end

View File

@ -45,24 +45,6 @@ describe Webrat::Configuration do
config.selenium_server_port.should == 1234
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
before :each do
@config = Webrat::Configuration.new

View File

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

View File

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

View File

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