Sets the Webrat mode with Configuration#mode= in the config block

This commit is contained in:
gaffo 2008-12-25 23:04:41 -05:00 committed by Bryan Helmkamp
parent 6d7fc04f71
commit 22c7834512
13 changed files with 37 additions and 18 deletions

View File

@ -19,6 +19,7 @@
* Maximize the browser window after initializing Selenium (Luke Melia)
* Better inspect output for Webrat elements
* Sets the Webrat mode with Configuration#mode= in the config block [#85] (Mike Gaffney)
* Detect if the document is XML or HTML using the Content-Type when in Rails mode
* Expose #selenium method for direct access to Selenium client
* Check nokogiri gem version before requiring nokogiri

View File

@ -61,7 +61,11 @@ 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 = :rails
end
== Install with Merb

View File

@ -17,6 +17,7 @@ module Webrat
# config.parse_with_nokogiri = false
# end
class Configuration
# Should XHTML be parsed with Nokogiri? Defaults to true, except on JRuby. When false, Hpricot and REXML are used
attr_writer :parse_with_nokogiri
@ -39,6 +40,13 @@ module Webrat
@open_error_files ? true : false
end
# Allows setting of webrat's mode, valid modes are:
# :rails, :selenium, :rack, :sinatra, :mechanize, :merb
def mode=(mode)
@mode = mode
require("webrat/#{mode}")
end
end
end

View File

@ -72,5 +72,3 @@ module Webrat #:nodoc:
end
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

@ -86,11 +86,8 @@ module ActionController #:nodoc:
end
end
end
IntegrationTest.class_eval do
include Webrat::Methods
include Webrat::Matchers
end
end
Webrat.configuration.mode = :rails

View File

@ -4,8 +4,6 @@ require "selenium/client"
require "webrat/selenium/selenium_session"
require "webrat/selenium/matchers"
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

@ -38,4 +38,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
[:rails,
:selenium,
:rack,
:sinatra,
:merb,
: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
end

View File

@ -3,7 +3,7 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
describe "Webrat::MechanizeSession" do
before :all do
Webrat.cache_config_for_test
require "webrat/mechanize"
Webrat.configuration.mode = :mechanize
end
after :all do

View File

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