Sha256: 536e9d9986a526d4d72339ff7177873b5fb7051f23d3abf464d037bf8ccbd91a

Contents?: true

Size: 1.56 KB

Versions: 2

Compression:

Stored size: 1.56 KB

Contents

require 'spec_helper'

describe Berkshelf::Config do
  subject { config }

  let(:config) { klass.new }
  let(:klass) { described_class }

  it { should be_valid }

  its(:present?) { should be_false }

  it "set and gets hash keys" do
    config[:a] = 1
    config[:a].should == 1
  end

  it "does not raise an error for nested hash keys that have not been set" do
    config[:d][:e]
  end

  it "has indifferent access" do
    config[:a] = 1
    config['b'] = 2

    config['a'].should == 1
    config[:b].should == 2
  end

  describe ".file" do
    subject { klass.file }

    context "when the file does not exist" do
      before :each do
        File.stub exists?: false
      end

      it { should be_nil }
    end
  end

  describe ".from_json" do
    subject(:config) { klass.from_json json }

    let(:json) {
      <<-JSON
        {
          "a": 1,
          "b": {
            "c": 2
          }
        }
      JSON
    }

    it "has data" do
      config[:a].should == 1
    end

    it "has nested data" do
      config[:b][:c].should == 2
    end

    it "does not raise an error for nested hash keys that have not been set" do
      config[:d][:e]
    end

    it "has indifferent access" do
      config['a'].should == 1
      config[:a].should == 1
    end

    context "with an invalid configuration" do
      let(:json) { '{ "wat": 1 }' }

      it { should_not be_valid }
    end
  end

  describe ".instance" do
    subject { klass.instance }

    it { should be_a klass }
  end

  describe ".path" do
    subject { klass.path }

    it { should be_a String }
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
berkshelf-0.6.0.beta4 spec/unit/berkshelf/config_spec.rb
berkshelf-0.6.0.beta3 spec/unit/berkshelf/config_spec.rb