diff --git a/lib/webrat.rb b/lib/webrat.rb index c4c5118..8798a65 100644 --- a/lib/webrat.rb +++ b/lib/webrat.rb @@ -3,14 +3,31 @@ require "rubygems" $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__))) unless $LOAD_PATH.include?(File.expand_path(File.dirname(__FILE__))) module Webrat + class WebratError < StandardError + end + VERSION = '0.3.2' def self.root #:nodoc: defined?(RAILS_ROOT) ? RAILS_ROOT : Merb.root end - class WebratError < StandardError + + # Configures Webrat. If this is not done, Webrat will be created + # with all of the default settings. + def self.configure(configuration = Webrat::Core::Configuration.new) + yield configuration if block_given? + @@configuration = configuration end + + def self.configuration + @@configuration = Webrat::Core::Configuration.new unless @@configuration + @@configuration + end + + private + @@configuration = nil + end # We need Nokogiri's CSS to XPath support, even if using REXML and Hpricot for parsing and searching diff --git a/lib/webrat/core/configuration.rb b/lib/webrat/core/configuration.rb index 722fc14..7078092 100755 --- a/lib/webrat/core/configuration.rb +++ b/lib/webrat/core/configuration.rb @@ -1,19 +1,6 @@ module Webrat module Core class Configuration - - # Configures Webrat. If this is not done, Webrat will be created - # with all of the default settings. - def self.configure(configuration = Webrat::Core::Configuration.new) - yield configuration if block_given? - @@configuration = configuration - end - - def self.configuration - @@configuration = Webrat::Core::Configuration.new unless @@configuration - @@configuration - end - # Sets whether to save and open pages with error status codes in a browser attr_accessor :open_error_files @@ -22,8 +9,6 @@ module Webrat end private - @@configuration = nil - def default_open_error_files true end diff --git a/lib/webrat/core/session.rb b/lib/webrat/core/session.rb index bbc71ec..fbf28f0 100644 --- a/lib/webrat/core/session.rb +++ b/lib/webrat/core/session.rb @@ -86,7 +86,7 @@ module Webrat send "#{http_method}", url, data || {}, h end - save_and_open_page if exception_caught? && !Webrat::Core::Configuration.configuration.open_error_files + save_and_open_page if exception_caught? && Webrat.configuration.open_error_files raise PageLoadError.new("Page load was not successful (Code: #{response_code.inspect}):\n#{formatted_error}") unless success_code? @_scopes = nil diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index be1c229..21bcdd0 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -12,11 +12,11 @@ Spec::Runner.configure do |config| end -class Webrat::Core::Configuration +module Webrat @@previous_config = nil def self.cache_config_for_test - @@configuration = Webrat::Core::Configuration.configuration + @@configuration = Webrat.configuration end def self.reset_for_test diff --git a/spec/webrat/core/configuration_spec.rb b/spec/webrat/core/configuration_spec.rb index d98bd04..2d6e8f0 100755 --- a/spec/webrat/core/configuration_spec.rb +++ b/spec/webrat/core/configuration_spec.rb @@ -3,27 +3,27 @@ require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper") describe Webrat::Core::Configuration do before do - Webrat::Core::Configuration.cache_config_for_test + Webrat.cache_config_for_test end after do - Webrat::Core::Configuration.reset_for_test + Webrat.reset_for_test end it "should have a default config" do - Webrat::Core::Configuration.configuration.should be_an_instance_of(Webrat::Core::Configuration) + Webrat.configuration.should be_an_instance_of(Webrat::Core::Configuration) end it "should set default values" do - config = Webrat::Core::Configuration.configuration + config = Webrat.configuration config.open_error_files.should == true end it "should be configurable with a block" do - Webrat::Core::Configuration.configure do |config| + Webrat.configure do |config| config.open_error_files = false end - config = Webrat::Core::Configuration.configuration + config = Webrat.configuration config.open_error_files.should == false end diff --git a/spec/webrat/core/session_spec.rb b/spec/webrat/core/session_spec.rb index 6d3b5e3..fe0d0b8 100644 --- a/spec/webrat/core/session_spec.rb +++ b/spec/webrat/core/session_spec.rb @@ -87,11 +87,11 @@ describe Webrat::Session do describe "#request_page" do before(:each) do - Webrat::Core::Configuration.cache_config_for_test + Webrat.cache_config_for_test @session = Webrat::Session.new end after(:each) do - Webrat::Core::Configuration.reset_for_test + Webrat.reset_for_test end it "should raise an error if the request is not a success" do @@ -105,6 +105,9 @@ describe Webrat::Session do end it "should raise an error but not open if the request is not a success and config quashes save_and_open" do + Webrat.configure do |config| + config.open_error_files = false + end @session.stub!(:get) @session.stub!(:response_body).and_return("Exception caught") @session.stub!(:response_code).and_return(500)