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:
defined?(RAILS_ROOT) ? RAILS_ROOT : Merb.root
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

View File

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

View File

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

View File

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