Sha256: 4e1b7e22ca95ec6aa03ff514be5d7ec8a0dbc951924aba96b445077c81153b85

Contents?: true

Size: 1.49 KB

Versions: 5

Compression:

Stored size: 1.49 KB

Contents

require 'spec_helper'

describe Berkshelf::Config do
  describe '::file' do
    context 'when the file does not exist' do
      before { allow(File).to receive(:exists?).and_return(false) }

      it 'is nil' do
        expect(Berkshelf::Config.file).to be_nil
      end
    end
  end

  describe '::instance' do
    it 'should be a Berkshelf::Config' do
      expect(Berkshelf::Config.instance).to be_an_instance_of(Berkshelf::Config)
    end

    context 'attributes' do
      it 'should have a default API timeout' do
        expect(Berkshelf::Config.instance.api.timeout).to eq('30')
      end
    end
  end

  describe '::path' do
    it 'is a string' do
      expect(Berkshelf::Config.path).to be_a(String)
    end

    before do
      allow(File).to receive(:exists?).and_return(false)
    end

    after do
      Berkshelf::Config.instance_variable_set(:@path, nil)
    end

    context "when ENV['BERKSHELF_CONFIG'] is used" do
      before do
        allow(ENV).to receive(:[]).with('BERKSHELF_CONFIG').and_return('/tmp/config.json')
        allow(File).to receive(:exists?).with('/tmp/config.json').and_return(true)
      end

      it "points to a location within it" do
        expect(Berkshelf::Config.path).to match(%r{/tmp/config.json})
      end
    end
  end

  describe "::set_path" do
    subject(:set_path) { described_class.set_path("/tmp/other_path.json") }

    it "sets the #instance to nil" do
      set_path
      expect(described_class.instance_variable_get(:@instance)).to be_nil
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
berkshelf-5.5.0 spec/unit/berkshelf/config_spec.rb
berkshelf-5.4.0 spec/unit/berkshelf/config_spec.rb
berkshelf-5.3.0 spec/unit/berkshelf/config_spec.rb
berkshelf-5.2.0 spec/unit/berkshelf/config_spec.rb
berkshelf-5.1.0 spec/unit/berkshelf/config_spec.rb