webrat config now does the require

This commit is contained in:
gaffo 2008-12-08 23:19:44 -06:00
parent 5f405ebbdc
commit 2811a089bc
16 changed files with 56 additions and 28 deletions

View File

@ -52,7 +52,10 @@ To install the latest code as a plugin: (_Note:_ This may be less stable than us
In your test_helper.rb, spec_helper.rb, or env.rb (for Cucumber) add:
require "webrat/rails"
require "webrat"
Webrat.configure do |config|
config.mode = Webrat::Configuration::RAILS_MODE
end
== Install with Merb

View File

@ -12,6 +12,14 @@ module Webrat
end
class Configuration
RAILS_MODE = :rails
SELENIUM_MODE = :selenium
RACK_MODE = :rack
SINATRA_MODE = :sinatra
MECHANIZE_MODE = :mechanize
MERB_MODE = :merb
# Should XHTML be parsed with Nokogiri? Defaults to true, except on JRuby. When false, Hpricot and REXML are used
attr_writer :parse_with_nokogiri
@ -34,6 +42,14 @@ module Webrat
@open_error_files ? true : false
end
# Allows setting of webrat's mode, valid modes are:
# RAILS_MODE - Used in typical rails development
# SELENIUM_MODE - Used for webrat in selenium mode
def mode=(mode)
@mode = mode
require("webrat/#{mode}")
end
end
end

View File

@ -80,9 +80,9 @@ module Webrat
return nil if disabled?
case Webrat.configuration.mode
when :rails
when Webrat::Configuration::RAILS_MODE
ActionController::AbstractRequest.parse_query_parameters("#{name}=#{escaped_value}")
when :merb
when Webrat::Configuration::MERB_MODE
::Merb::Parse.query("#{name}=#{escaped_value}")
else
{ name => escaped_value }

View File

@ -144,9 +144,9 @@ module Webrat
klasses = [Hash]
case Webrat.configuration.mode
when :rails
when Webrat::Configuration::RAILS_MODE
klasses << HashWithIndifferentAccess
when :merb
when Webrat::Configuration::MERB_MODE
klasses << Mash
end

View File

@ -8,9 +8,9 @@ module Webrat
def logger # :nodoc:
case Webrat.configuration.mode
when :rails
when Webrat::Configuration::RAILS_MODE
defined?(RAILS_DEFAULT_LOGGER) ? RAILS_DEFAULT_LOGGER : nil
when :merb
when Webrat::Configuration::MERB_MODE
Merb.logger
else
nil

View File

@ -10,17 +10,17 @@ module Webrat
def self.session_class
case Webrat.configuration.mode
when :rails
when Webrat::Configuration::RAILS_MODE
RailsSession
when :merb
when Webrat::Configuration::MERB_MODE
MerbSession
when :selenium
when Webrat::Configuration::SELENIUM_MODE
SeleniumSession
when :rack
when Webrat::Configuration::RACK_MODE
RackSession
when :sinatra
when Webrat::Configuration::SINATRA_MODE
SinatraSession
when :mechanize
when Webrat::Configuration::MECHANIZE_MODE
MechanizeSession
else
raise WebratError.new("Unknown Webrat mode: #{Webrat.configuration.mode.inspect}")

View File

@ -39,5 +39,3 @@ module Webrat #:nodoc:
end
end
Webrat.configuration.mode = :mechanize

View File

@ -72,6 +72,3 @@ class Merb::Test::RspecStory #:nodoc:
@browser ||= Webrat::MerbSession.new
end
end
Webrat.configuration.mode = :merb

View File

@ -22,5 +22,3 @@ module Webrat
end
end
end
Webrat.configuration.mode = :rack

View File

@ -81,5 +81,3 @@ module ActionController #:nodoc:
end
end
end
Webrat.configuration.mode = :rails

View File

@ -3,8 +3,6 @@ gem "selenium-client", ">=1.2.9"
require "selenium/client"
require "webrat/selenium/selenium_session"
Webrat.configuration.mode = :selenium
module Webrat
def self.with_selenium_server #:nodoc:

View File

@ -17,5 +17,3 @@ module Webrat
end
end
Webrat.configuration.mode = :sinatra

View File

@ -18,6 +18,7 @@ Spec::Runner.configure do |config|
def with_html(html)
webrat_session.response_body = html
end
end
module Webrat
@ -30,4 +31,10 @@ module Webrat
def self.reset_for_test
@@configuration = @@previous_config if @@previous_config
end
class Configuration
def mode_for_test= (mode)
@mode = mode
end
end
end

View File

@ -41,4 +41,17 @@ describe Webrat::Configuration do
config = Webrat.configuration
config.should_not open_error_files
end
[Webrat::Configuration::RAILS_MODE,
Webrat::Configuration::SELENIUM_MODE,
Webrat::Configuration::RACK_MODE,
Webrat::Configuration::SINATRA_MODE,
Webrat::Configuration::MERB_MODE,
Webrat::Configuration::MECHANIZE_MODE].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
end

View File

@ -3,6 +3,7 @@ require "mechanize"
require "webrat/mechanize"
describe Webrat::MechanizeSession do
before(:each) do
@mech = Webrat::MechanizeSession.new
end

View File

@ -7,3 +7,4 @@ silence_warnings do
end
require "webrat/rails"
Webrat.configuration.mode_for_test = Webrat::Configuration::RAILS_MODE