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:
|
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
|
== Install with Merb
|
||||||
|
|
||||||
|
@ -12,6 +12,14 @@ module Webrat
|
|||||||
end
|
end
|
||||||
|
|
||||||
class Configuration
|
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
|
# Should XHTML be parsed with Nokogiri? Defaults to true, except on JRuby. When false, Hpricot and REXML are used
|
||||||
attr_writer :parse_with_nokogiri
|
attr_writer :parse_with_nokogiri
|
||||||
|
|
||||||
@ -34,6 +42,14 @@ module Webrat
|
|||||||
@open_error_files ? true : false
|
@open_error_files ? true : false
|
||||||
end
|
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
|
||||||
|
|
||||||
end
|
end
|
@ -80,9 +80,9 @@ module Webrat
|
|||||||
return nil if disabled?
|
return nil if disabled?
|
||||||
|
|
||||||
case Webrat.configuration.mode
|
case Webrat.configuration.mode
|
||||||
when :rails
|
when Webrat::Configuration::RAILS_MODE
|
||||||
ActionController::AbstractRequest.parse_query_parameters("#{name}=#{escaped_value}")
|
ActionController::AbstractRequest.parse_query_parameters("#{name}=#{escaped_value}")
|
||||||
when :merb
|
when Webrat::Configuration::MERB_MODE
|
||||||
::Merb::Parse.query("#{name}=#{escaped_value}")
|
::Merb::Parse.query("#{name}=#{escaped_value}")
|
||||||
else
|
else
|
||||||
{ name => escaped_value }
|
{ name => escaped_value }
|
||||||
|
@ -144,9 +144,9 @@ module Webrat
|
|||||||
klasses = [Hash]
|
klasses = [Hash]
|
||||||
|
|
||||||
case Webrat.configuration.mode
|
case Webrat.configuration.mode
|
||||||
when :rails
|
when Webrat::Configuration::RAILS_MODE
|
||||||
klasses << HashWithIndifferentAccess
|
klasses << HashWithIndifferentAccess
|
||||||
when :merb
|
when Webrat::Configuration::MERB_MODE
|
||||||
klasses << Mash
|
klasses << Mash
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -8,9 +8,9 @@ module Webrat
|
|||||||
|
|
||||||
def logger # :nodoc:
|
def logger # :nodoc:
|
||||||
case Webrat.configuration.mode
|
case Webrat.configuration.mode
|
||||||
when :rails
|
when Webrat::Configuration::RAILS_MODE
|
||||||
defined?(RAILS_DEFAULT_LOGGER) ? RAILS_DEFAULT_LOGGER : nil
|
defined?(RAILS_DEFAULT_LOGGER) ? RAILS_DEFAULT_LOGGER : nil
|
||||||
when :merb
|
when Webrat::Configuration::MERB_MODE
|
||||||
Merb.logger
|
Merb.logger
|
||||||
else
|
else
|
||||||
nil
|
nil
|
||||||
|
@ -10,17 +10,17 @@ module Webrat
|
|||||||
|
|
||||||
def self.session_class
|
def self.session_class
|
||||||
case Webrat.configuration.mode
|
case Webrat.configuration.mode
|
||||||
when :rails
|
when Webrat::Configuration::RAILS_MODE
|
||||||
RailsSession
|
RailsSession
|
||||||
when :merb
|
when Webrat::Configuration::MERB_MODE
|
||||||
MerbSession
|
MerbSession
|
||||||
when :selenium
|
when Webrat::Configuration::SELENIUM_MODE
|
||||||
SeleniumSession
|
SeleniumSession
|
||||||
when :rack
|
when Webrat::Configuration::RACK_MODE
|
||||||
RackSession
|
RackSession
|
||||||
when :sinatra
|
when Webrat::Configuration::SINATRA_MODE
|
||||||
SinatraSession
|
SinatraSession
|
||||||
when :mechanize
|
when Webrat::Configuration::MECHANIZE_MODE
|
||||||
MechanizeSession
|
MechanizeSession
|
||||||
else
|
else
|
||||||
raise WebratError.new("Unknown Webrat mode: #{Webrat.configuration.mode.inspect}")
|
raise WebratError.new("Unknown Webrat mode: #{Webrat.configuration.mode.inspect}")
|
||||||
|
@ -39,5 +39,3 @@ module Webrat #:nodoc:
|
|||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
Webrat.configuration.mode = :mechanize
|
|
@ -72,6 +72,3 @@ class Merb::Test::RspecStory #:nodoc:
|
|||||||
@browser ||= Webrat::MerbSession.new
|
@browser ||= Webrat::MerbSession.new
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
Webrat.configuration.mode = :merb
|
|
||||||
|
|
||||||
|
@ -22,5 +22,3 @@ module Webrat
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
Webrat.configuration.mode = :rack
|
|
@ -80,6 +80,4 @@ module ActionController #:nodoc:
|
|||||||
include Webrat::Methods
|
include Webrat::Methods
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
Webrat.configuration.mode = :rails
|
|
@ -3,8 +3,6 @@ gem "selenium-client", ">=1.2.9"
|
|||||||
require "selenium/client"
|
require "selenium/client"
|
||||||
require "webrat/selenium/selenium_session"
|
require "webrat/selenium/selenium_session"
|
||||||
|
|
||||||
Webrat.configuration.mode = :selenium
|
|
||||||
|
|
||||||
module Webrat
|
module Webrat
|
||||||
|
|
||||||
def self.with_selenium_server #:nodoc:
|
def self.with_selenium_server #:nodoc:
|
||||||
|
@ -17,5 +17,3 @@ module Webrat
|
|||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
Webrat.configuration.mode = :sinatra
|
|
@ -18,6 +18,7 @@ Spec::Runner.configure do |config|
|
|||||||
def with_html(html)
|
def with_html(html)
|
||||||
webrat_session.response_body = html
|
webrat_session.response_body = html
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
module Webrat
|
module Webrat
|
||||||
@ -30,4 +31,10 @@ module Webrat
|
|||||||
def self.reset_for_test
|
def self.reset_for_test
|
||||||
@@configuration = @@previous_config if @@previous_config
|
@@configuration = @@previous_config if @@previous_config
|
||||||
end
|
end
|
||||||
|
|
||||||
|
class Configuration
|
||||||
|
def mode_for_test= (mode)
|
||||||
|
@mode = mode
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
@ -3,7 +3,7 @@ require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper")
|
|||||||
describe Webrat::Configuration do
|
describe Webrat::Configuration do
|
||||||
predicate_matchers[:parse_with_nokogiri] = :parse_with_nokogiri?
|
predicate_matchers[:parse_with_nokogiri] = :parse_with_nokogiri?
|
||||||
predicate_matchers[:open_error_files] = :open_error_files?
|
predicate_matchers[:open_error_files] = :open_error_files?
|
||||||
|
|
||||||
before do
|
before do
|
||||||
Webrat.cache_config_for_test
|
Webrat.cache_config_for_test
|
||||||
end
|
end
|
||||||
@ -41,4 +41,17 @@ describe Webrat::Configuration do
|
|||||||
config = Webrat.configuration
|
config = Webrat.configuration
|
||||||
config.should_not open_error_files
|
config.should_not open_error_files
|
||||||
end
|
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
|
end
|
@ -3,6 +3,7 @@ require "mechanize"
|
|||||||
require "webrat/mechanize"
|
require "webrat/mechanize"
|
||||||
|
|
||||||
describe Webrat::MechanizeSession do
|
describe Webrat::MechanizeSession do
|
||||||
|
|
||||||
before(:each) do
|
before(:each) do
|
||||||
@mech = Webrat::MechanizeSession.new
|
@mech = Webrat::MechanizeSession.new
|
||||||
end
|
end
|
||||||
|
@ -7,3 +7,4 @@ silence_warnings do
|
|||||||
end
|
end
|
||||||
|
|
||||||
require "webrat/rails"
|
require "webrat/rails"
|
||||||
|
Webrat.configuration.mode_for_test = Webrat::Configuration::RAILS_MODE
|
||||||
|
Loading…
Reference in New Issue
Block a user