Sha256: 922e3d023f63cbc312d076539f41b27b1a6e2212985e57ad5b4a7d1d718094be

Contents?: true

Size: 1.94 KB

Versions: 4

Compression:

Stored size: 1.94 KB

Contents

require 'spec_helper'

module Config::Sources
  describe YAMLSource do
    it "should take a path as initializer" do
      source = YAMLSource.new "somepath"
      expect(source.path).to eq("somepath")
    end

    context "basic yml file" do
      let(:source) do
        YAMLSource.new "#{fixture_path}/development.yml"
      end

      it "should properly read the settings" do
        results = source.load
        expect(results["size"]).to eq(2)
      end

      it "should properly read nested settings" do
        results = source.load
        expect(results["section"]["size"]).to eq(3)
        expect(results["section"]["servers"]).to be_instance_of(Array)
        expect(results["section"]["servers"].size).to eq(2)
      end
    end

    context "yml file with erb tags" do
      let(:source) do
        YAMLSource.new "#{fixture_path}/with_erb.yml"
      end

      it "should properly evaluate the erb" do
        results = source.load
        expect(results["computed"]).to eq(6)
      end

      it "should properly evaluate the nested erb settings" do
        results = source.load
        expect(results["section"]["computed1"]).to eq(1)
        expect(results["section"]["computed2"]).to eq(2)
      end
    end

    context "missing yml file" do
      let(:source) do
        YAMLSource.new "somewhere_that_doesnt_exist.yml"
      end

      it "should return an empty hash" do
        results = source.load
        expect(results).to eq({})
      end
    end

    context "blank yml file" do
      let(:source) do
        YAMLSource.new "#{fixture_path}/empty1.yml"
      end

      it "should return an empty hash" do
        results = source.load
        expect(results).to eq({})
      end
    end

    context "malformed yml file" do
      let(:source) do
        YAMLSource.new "#{fixture_path}/malformed.yml"
      end

      it "should raise an useful exception" do
        expect { source.load }.to raise_error(/malformed\.yml/)
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
config-1.0.0 spec/sources/yaml_source_spec.rb
config-1.0.0.beta3 spec/sources/yaml_source_spec.rb
config-1.0.0.beta2 spec/sources/yaml_source_spec.rb
config-1.0.0.beta1 spec/sources/yaml_source_spec.rb