Sha256: b9a6ffca3becaa1fd8a17776091f9062260106a784405380f775b52475b3ab1c

Contents?: true

Size: 1.52 KB

Versions: 2

Compression:

Stored size: 1.52 KB

Contents

require "spec_helper"

module RockConfig
  describe Config do
    it "accepts a hash" do
      hash = {:foo => "bar"}

      config = Config.new(hash)
      config.raw.should eq(hash)
    end

    it "returns config for given environment" do
      subhash_dev  = {"a" => 123}
      subhash_prod = {"a" => 321}
      hash = {
        "development" => subhash_dev,
        "production"  => subhash_prod
      }

      config = Config.new(hash)
      config.development.raw.should eq(subhash_dev)
      config.production.raw.should eq(subhash_prod)
    end

    it "returns nil when asked for non existing environment" do
      config = Config.new({})
      config.for_environment("I do not exist").should be_nil
    end

    it "returns correct values when asked for" do
      hash = {
        "development" => {
          "host" => "localhost"
        }
      }

      config = Config.new(hash)
      config.development.host.should eq("localhost")
    end

    it "returns correct nested values when asked for" do
      hash = {
        "development" => {
          "elastic" => {
            "host" => "localhost"
          }
        }
      }

      config = Config.new(hash)
      config.development.elastic.host.should eq("localhost")
    end

    it "supports accessing the values by brackets" do
      hash = {
        "development" => {
          "elastic" => {
            "host" => "localhost"
          }
        }
      }

      config = Config.new(hash)
      config["development"]["elastic"]["host"].should eq("localhost")
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rock_config-0.0.5 spec/config_spec.rb
rock_config-0.0.4 spec/config_spec.rb