spec/unit/berkshelf/config_spec.rb in berkshelf-1.4.6 vs spec/unit/berkshelf/config_spec.rb in berkshelf-2.0.0.beta
- old
+ new
@@ -1,39 +1,55 @@
require 'spec_helper'
describe Berkshelf::Config do
- let(:klass) { described_class }
+ describe '.file' do
+ context 'when the file does not exist' do
+ before { File.stub(:exists?).and_return(false) }
- describe "ClassMethods" do
- subject { klass }
+ it 'is nil' do
+ expect(Berkshelf::Config.file).to be_nil
+ end
+ end
+ end
- describe "::file" do
- subject { klass.file }
+ describe '.instance' do
+ it 'should be a Berkshelf::Config' do
+ expect(Berkshelf::Config.instance).to be_an_instance_of(Berkshelf::Config)
+ end
+ end
- context "when the file does not exist" do
- before :each do
- File.stub exists?: false
- end
+ describe '.path' do
+ it 'is a string' do
+ expect(Berkshelf::Config.path).to be_a(String)
+ end
- it { should be_nil }
- end
+ before do
+ File.stub(:exists?).and_return(false)
end
- describe "::instance" do
- subject { klass.instance }
-
- it { should be_a klass }
+ after do
+ Berkshelf::Config.instance_variable_set(:@path, nil)
end
- describe "::path" do
- subject { klass.path }
+ Berkshelf::Config::LOCATIONS.each do |location|
+ context "with '#{location}' as the config file" do
+ let(:path) { File.expand_path(location) }
+ before { File.stub(:exists?).with(path).and_return(true) }
- it { should be_a String }
+ it "returns '#{location}' as the path" do
+ expect(Berkshelf::Config.path).to eq(path)
+ end
+ end
+ end
- it "points to a location within ENV['BERKSHELF_PATH']" do
+ context "when ENV['BERKSHELF_PATH'] is used" do
+ before do
ENV.stub(:[]).with('BERKSHELF_PATH').and_return('/tmp')
+ File.stub(:exists?).with('/tmp').and_return(true)
+ end
- subject.should eql("/tmp/config.json")
+ it "points to a location within it" do
+ expect(Berkshelf::Config.path).to eq('/tmp/config.json')
end
end
end
end