Skip to content

Commit

Permalink
Collapsing Webrat::Core module. Moving configuration methods to confi…
Browse files Browse the repository at this point in the history
…guration.rb
  • Loading branch information
brynary committed Nov 16, 2008
1 parent 9f8a88d commit 31cc6b7
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 63 deletions.
16 changes: 0 additions & 16 deletions lib/webrat.rb
Expand Up @@ -11,22 +11,6 @@ class WebratError < StandardError
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

Expand Down
40 changes: 23 additions & 17 deletions lib/webrat/core/configuration.rb
@@ -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
1 change: 0 additions & 1 deletion spec/spec_helper.rb
Expand Up @@ -11,7 +11,6 @@
# Nothing to configure yet
end


module Webrat
@@previous_config = nil

Expand Down
56 changes: 27 additions & 29 deletions spec/webrat/core/configuration_spec.rb
@@ -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

0 comments on commit 31cc6b7

Please sign in to comment.