Sha256: 0c2cdb76b0f3e3fa350d1a95b0be369c5ecd228b2c696550d5410159bb8e02d7

Contents?: true

Size: 2 KB

Versions: 17

Compression:

Stored size: 2 KB

Contents

require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')

describe "Configliere::Param" do
  before do
    @config = Configliere::Param.new :hat => :cat, :basket => :lotion, :moon => { :man => :smiling }
  end

  describe '#defaults' do
    it 'deep_merges new params' do
      @config.defaults :basket => :tasket, :moon => { :cow => :jumping }
      @config.should == { :hat => :cat, :basket => :tasket, :moon => { :man => :smiling, :cow => :jumping } }
    end
  end

  describe '#[]=' do
    it 'symbolizes keys' do
      @config['hat'] = :fedora
      @config['new'] = :unseen
#      @config.should == { :hat => :fedora, :basket => :lotion, :new => :unseen, :moon => { :man => :smiling } }
    end
    it 'deep-sets dotted vals, replacing values' do
      @config['moon.man'] = :cheesy
      @config[:moon][:man].should == :cheesy
    end
    it 'deep-sets dotted vals, creating new values' do
      @config['moon.cheese.type'] = :tilsit
      @config[:moon][:cheese][:type].should == :tilsit
    end
    it 'deep-sets dotted vals, auto-vivifying intermediate hashes' do
      @config['this.that.the_other'] = :fuhgeddaboudit
      @config[:this][:that][:the_other].should == :fuhgeddaboudit
    end
  end

  describe '#[]' do
    it 'deep-gets dotted vals' do
      hsh = { :hat => :cat, :basket => :lotion, :moon => { :man => :smiling, :cheese => {:type => :tilsit} } }
      @config = Configliere::Param.new hsh.dup
      @config['moon.man'].should == :smiling
      @config['moon.cheese.type'].should == :tilsit
      @config['moon.cheese.smell'].should be_nil
      @config['moon.non.existent.interim.values'].should be_nil
      @config['moon.non'].should be_nil
      if (RUBY_VERSION >= '1.9') then lambda{ @config['hat.cat'] }.should raise_error(TypeError)
      else                            lambda{ @config['hat.cat'] }.should raise_error(NoMethodError, 'undefined method `[]\' for :cat:Symbol') end
      @config.should == hsh # shouldn't change from reading (specifically, shouldn't autovivify)
    end
  end

end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
configliere-0.3.4 spec/configliere/param_spec.rb
configliere-0.3.3 spec/configliere/param_spec.rb
configliere-0.2.3 spec/configliere/param_spec.rb
configliere-0.3.2 spec/configliere/param_spec.rb
configliere-0.3.1 spec/configliere/param_spec.rb
configliere-0.3.0 spec/configliere/param_spec.rb
configliere-0.2.2 spec/configliere/param_spec.rb
configliere-0.2.1 spec/configliere/param_spec.rb
configliere-0.1.1 spec/configliere/param_spec.rb
configliere-0.1.0 spec/configliere/param_spec.rb
configliere-0.0.9 spec/configliere/param_spec.rb
configliere-0.0.8 spec/configliere/param_spec.rb
configliere-0.0.7 spec/configliere/param_spec.rb
configliere-0.0.6 spec/configliere/param_spec.rb
configliere-0.0.5 spec/configliere/param_spec.rb
configliere-0.0.4 spec/configliere/param_spec.rb
configliere-0.0.3 spec/configliere/param_spec.rb