Sha256: b080445b9bb557fee8f91018988516a3ab0c07dcd0d9f549f1082bc12153d2b6

Contents?: true

Size: 1.98 KB

Versions: 7

Compression:

Stored size: 1.98 KB

Contents

require 'spec_helper'

module MyApp; end

describe Configoro do
  subject { MyApp::Configuration }

  describe "#initialize" do
    it "should make the configuration available to MyApp::Configuration" do
      subject.should be_kind_of(Configoro::Hash)
    end

    it "should load data from the config files" do
      subject.basic.common_only.should eql('common')
    end

    it "should give priority to environment-specific files" do
      subject.basic.env_name.should eql('development')
    end

    it "should not load data from other environments" do
      subject.basic['should_not_exist'].should be_nil
    end

    it "should convert hashes recursively" do
      subject.hash_test.akey.should eql('value')
    end

    it "should deep-merge hashes" do
      subject.hash_test.subhash.key1.should eql('val1')
      subject.hash_test.subhash.key2.should eql('newval')
    end

    it "should not complain when there is no directory for the current environment" do
      Rails.stub!(:env).and_return('unknown')
      Configoro.initialize
      MyApp::Configuration.should eql({"basic"=>{"common_only"=>"common", "env_name"=>"common"}, "erb_test" => {"sum" => 2}, "hash_test"=>{"akey"=>"value", "subhash"=>{"key1"=>"val1", "key2"=>"val2"}}})
    end

    context "[custom search paths]" do
      before(:each) { Configoro.instance_variable_set :@paths, nil }

      it "should use common configuration under a custom search path" do
        Rails.stub!(:env).and_return('unknown')
        Configoro.paths << File.join(File.dirname(__FILE__), 'data', 'other')
        Configoro.initialize
        MyApp::Configuration.basic.env_name.should eql('other_common')
      end

      it "should use environment-specific configuration under a custom search path" do
        Rails.stub!(:env).and_return('development')
        Configoro.paths << File.join(File.dirname(__FILE__), 'data', 'other')
        Configoro.initialize
        MyApp::Configuration.basic.env_name.should eql('other_development')
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
configoro-1.4.0 spec/configoro_spec.rb
configoro-1.3.0 spec/configoro_spec.rb
configoro-1.2.4 spec/configoro_spec.rb
configoro-1.2.3 spec/configoro_spec.rb
configoro-1.2.2 spec/configoro_spec.rb
configoro-1.2.1 spec/configoro_spec.rb
configoro-1.2.0 spec/configoro_spec.rb