webrat config now does the require
This commit is contained in:
parent
5f405ebbdc
commit
2811a089bc
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
|
@ -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 }
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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}")
|
||||
|
|
|
@ -39,5 +39,3 @@ module Webrat #:nodoc:
|
|||
|
||||
end
|
||||
end
|
||||
|
||||
Webrat.configuration.mode = :mechanize
|
|
@ -72,6 +72,3 @@ class Merb::Test::RspecStory #:nodoc:
|
|||
@browser ||= Webrat::MerbSession.new
|
||||
end
|
||||
end
|
||||
|
||||
Webrat.configuration.mode = :merb
|
||||
|
||||
|
|
|
@ -22,5 +22,3 @@ module Webrat
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
Webrat.configuration.mode = :rack
|
|
@ -80,6 +80,4 @@ module ActionController #:nodoc:
|
|||
include Webrat::Methods
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Webrat.configuration.mode = :rails
|
||||
end
|
|
@ -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:
|
||||
|
|
|
@ -17,5 +17,3 @@ module Webrat
|
|||
|
||||
end
|
||||
end
|
||||
|
||||
Webrat.configuration.mode = :sinatra
|
|
@ -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
|
|
@ -3,7 +3,7 @@ require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper")
|
|||
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
|
||||
|
@ -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
|
|
@ -3,6 +3,7 @@ require "mechanize"
|
|||
require "webrat/mechanize"
|
||||
|
||||
describe Webrat::MechanizeSession do
|
||||
|
||||
before(:each) do
|
||||
@mech = Webrat::MechanizeSession.new
|
||||
end
|
||||
|
|
|
@ -7,3 +7,4 @@ silence_warnings do
|
|||
end
|
||||
|
||||
require "webrat/rails"
|
||||
Webrat.configuration.mode_for_test = Webrat::Configuration::RAILS_MODE
|
||||
|
|
Loading…
Reference in New Issue