Sha256: cfae74226bd2c6ffb5bef50f6b051a5ee8b289848323f8ba7df025ea0a6294a1

Contents?: true

Size: 1.79 KB

Versions: 4

Compression:

Stored size: 1.79 KB

Contents

require 'pathname'
require Pathname(__FILE__).dirname.expand_path.parent + 'spec_helper'

describe Configatron::Store do
  
  before :each do
    configatron.reset!
  end
  
  describe "namespace" do
    
    it "should let you 'namespace' a set of configuration parameters" do
      lambda{configatron.foo}.should raise_error(NoMethodError)
      configatron do |config|
        config.namespace(:foo) do |foo|
          foo.bar = :bar
        end
      end
      configatron.foo.bar.should == :bar
    end
    
    it "should raise NoMethodError if nil_for_missing is set to false" do
      lambda{configatron.foo}.should raise_error(NoMethodError)
      configatron do |config|
        config.namespace(:foo) do |foo|
          foo.bar = :bar
        end
      end
      lambda{configatron.foo.say_hello}.should raise_error(NoMethodError)
    end
    
    it "should allow for unlimited nested namespaces" do
      configatron do |config|
        config.namespace(:foo) do |foo|
          foo.bar = :bar
          foo.namespace(:apples) do |apps|
            apps.granny_smith = "Granny Smith"
            apps.red = "Red"
          end
        end
      end
      configatron.foo.bar.should == :bar
      configatron.foo.apples.granny_smith.should == "Granny Smith"
    end
    
    it "should not override all parameters when you namespace" do
      configatron do |config|
        config.namespace(:foo) do |foo|
          foo.bar = :bar
          foo.name = "mark"
        end
      end
      configatron.foo.bar.should == :bar
      configatron.foo.name.should == "mark"
      
      configatron do |config|
        config.namespace(:foo) do |foo|
          foo.name = "mark bates"
        end
      end
      
      configatron.foo.bar.should == :bar
      configatron.foo.name.should == "mark bates"
    end
    
  end
  
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
configatron-1.1.0 spec/unit/store_spec.rb
configatron-1.0.1 spec/unit/store_spec.rb
configatron-1.0.0 spec/unit/store_spec.rb
configatron-1.2.0 spec/unit/store_spec.rb