Collapsing Webrat::Core module. Moving configuration methods to configuration.rb

This commit is contained in:
Bryan Helmkamp 2008-11-16 18:58:24 -05:00
parent 9f8a88d649
commit 31cc6b75da
4 changed files with 50 additions and 63 deletions

View File

@ -11,22 +11,6 @@ module Webrat
def self.root #:nodoc: def self.root #:nodoc:
defined?(RAILS_ROOT) ? RAILS_ROOT : Merb.root defined?(RAILS_ROOT) ? RAILS_ROOT : Merb.root
end end
# 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 end

View File

@ -1,18 +1,24 @@
module Webrat module Webrat
module Core
class Configuration # Configures Webrat. If this is not done, Webrat will be created
# Sets whether to save and open pages with error status codes in a browser # with all of the default settings.
attr_accessor :open_error_files def self.configure(configuration = Webrat::Configuration.new)
yield configuration if block_given?
def initialize @@configuration = configuration
self.open_error_files = default_open_error_files end
end
def self.configuration
private @@configuration ||= Webrat::Configuration.new
def default_open_error_files end
true
end class Configuration
# Sets whether to save and open pages with error status codes in a browser
end attr_accessor :open_error_files
end
def initialize
self.open_error_files = true
end
end
end end

View File

@ -11,7 +11,6 @@ Spec::Runner.configure do |config|
# Nothing to configure yet # Nothing to configure yet
end end
module Webrat module Webrat
@@previous_config = nil @@previous_config = nil

View File

@ -1,30 +1,28 @@
require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper") require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper")
describe Webrat::Core::Configuration do describe Webrat::Configuration do
before do
before do Webrat.cache_config_for_test
Webrat.cache_config_for_test end
end
after do
after do Webrat.reset_for_test
Webrat.reset_for_test end
end
it "should have a default config" do
it "should have a default config" do Webrat.configuration.should be_an_instance_of(Webrat::Configuration)
Webrat.configuration.should be_an_instance_of(Webrat::Core::Configuration) end
end
it "should set default values" do
it "should set default values" do config = Webrat.configuration
config = Webrat.configuration config.open_error_files.should == true
config.open_error_files.should == true end
end
it "should be configurable with a block" do
it "should be configurable with a block" do Webrat.configure do |config|
Webrat.configure do |config| config.open_error_files = false
config.open_error_files = false end
end config = Webrat.configuration
config = Webrat.configuration config.open_error_files.should == false
config.open_error_files.should == false end
end
end end