spec/unit/berkshelf/locations/git_spec.rb in berkshelf-3.1.5 vs spec/unit/berkshelf/locations/git_spec.rb in berkshelf-3.2.0

- old
+ new

@@ -75,70 +75,70 @@ end end describe '#installed?' do it 'returns false when there is no revision' do - subject.stub(:revision).and_return(nil) - expect(subject.installed?).to be_false + allow(subject).to receive(:revision).and_return(nil) + expect(subject.installed?).to be(false) end it 'returns false when the install_path does not exist' do - subject.stub(:revision).and_return('abcd1234') - subject.stub(:install_path).and_return(double(exist?: false)) - expect(subject.installed?).to be_false + allow(subject).to receive(:revision).and_return('abcd1234') + allow(subject).to receive(:install_path).and_return(double(exist?: false)) + expect(subject.installed?).to be(false) end it 'returns true when the location is installed' do - subject.stub(:revision).and_return('abcd1234') - subject.stub(:install_path).and_return(double(exist?: true)) - expect(subject.installed?).to be_true + allow(subject).to receive(:revision).and_return('abcd1234') + allow(subject).to receive(:install_path).and_return(double(exist?: true)) + expect(subject.installed?).to be(true) end end describe '#install' do before do - File.stub(:chmod) - FileUtils.stub(:cp_r) - subject.stub(:validate_cached!) - subject.stub(:git) + allow(File).to receive(:chmod) + allow(FileUtils).to receive(:cp_r) + allow(subject).to receive(:validate_cached!) + allow(subject).to receive(:git) end context 'when the repository is cached' do it 'pulls a new version' do - Dir.stub(:chdir) { |args, &b| b.call } # Force eval the chdir block + allow(Dir).to receive(:chdir) { |args, &b| b.call } # Force eval the chdir block - subject.stub(:cached?).and_return(true) + allow(subject).to receive(:cached?).and_return(true) expect(subject).to receive(:git).with( 'fetch --force --tags https://repo.com "refs/heads/*:refs/heads/*"' ) subject.install end end context 'when the revision is not cached' do it 'clones the repository' do - Dir.stub(:chdir) { |args, &b| b.call } # Force eval the chdir block + allow(Dir).to receive(:chdir) { |args, &b| b.call } # Force eval the chdir block cache_path = subject.send(:cache_path) - subject.stub(:cached?).and_return(false) + allow(subject).to receive(:cached?).and_return(false) expect(subject).to receive(:git).with( %|clone https://repo.com "#{cache_path}" --bare --no-hardlinks| ) subject.install end end end describe '#cached_cookbook' do it 'returns nil if the cookbook is not installed' do - subject.stub(:installed?).and_return(false) + allow(subject).to receive(:installed?).and_return(false) expect(subject.cached_cookbook).to be_nil end it 'returns the cookbook at the install_path' do - subject.stub(:installed?).and_return(true) - CachedCookbook.stub(:from_path) + allow(subject).to receive(:installed?).and_return(true) + allow(CachedCookbook).to receive(:from_path) expect(CachedCookbook).to receive(:from_path).once subject.cached_cookbook end end @@ -149,58 +149,58 @@ it 'returns true when everything matches' do expect(subject).to eq(other) end it 'returns false when the other location is not an GitLocation' do - other.stub(:is_a?).and_return(false) + allow(other).to receive(:is_a?).and_return(false) expect(subject).to_not eq(other) end it 'returns false when the uri is different' do - other.stub(:uri).and_return('different') + allow(other).to receive(:uri).and_return('different') expect(subject).to_not eq(other) end it 'returns false when the branch is different' do - other.stub(:branch).and_return('different') + allow(other).to receive(:branch).and_return('different') expect(subject).to_not eq(other) end it 'returns false when the tag is different' do - other.stub(:tag).and_return('different') + allow(other).to receive(:tag).and_return('different') expect(subject).to_not eq(other) end it 'returns false when the ref is different' do - other.stub(:ref).and_return('different') + allow(other).to receive(:ref).and_return('different') expect(subject).to_not eq(other) end it 'returns false when the rel is different' do - other.stub(:rel).and_return('different') + allow(other).to receive(:rel).and_return('different') expect(subject).to_not eq(other) end end describe '#to_s' do it 'prefers the tag' do expect(subject.to_s).to eq('https://repo.com (at v1.2.3/hi)') end it 'prefers the branch' do - subject.stub(:tag).and_return(nil) + allow(subject).to receive(:tag).and_return(nil) expect(subject.to_s).to eq('https://repo.com (at ham/hi)') end it 'falls back to the ref' do - subject.stub(:tag).and_return(nil) - subject.stub(:branch).and_return(nil) + allow(subject).to receive(:tag).and_return(nil) + allow(subject).to receive(:branch).and_return(nil) expect(subject.to_s).to eq('https://repo.com (at abc123/hi)') end it 'does not use the rel if missing' do - subject.stub(:rel).and_return(nil) + allow(subject).to receive(:rel).and_return(nil) expect(subject.to_s).to eq('https://repo.com (at v1.2.3)') end end describe '#to_lock' do @@ -214,35 +214,35 @@ rel: hi EOH end it 'does not include the branch if missing' do - subject.stub(:branch).and_return(nil) + allow(subject).to receive(:branch).and_return(nil) expect(subject.to_lock).to_not include('branch') end it 'does not include the tag if missing' do - subject.stub(:tag).and_return(nil) + allow(subject).to receive(:tag).and_return(nil) expect(subject.to_lock).to_not include('tag') end it 'does not include the rel if missing' do - subject.stub(:rel).and_return(nil) + allow(subject).to receive(:rel).and_return(nil) expect(subject.to_lock).to_not include('rel') end end describe '#git' do before { described_class.send(:public, :git) } it 'raises an error if Git is not installed' do - Berkshelf.stub(:which).and_return(false) + allow(Berkshelf).to receive(:which).and_return(false) expect { subject.git('foo') }.to raise_error(GitNotInstalled) end it 'raises an error if the command fails' do shell_out = double('shell_out', success?: false, stderr: nil) - Buff::ShellOut.stub(:shell_out).and_return(shell_out) + allow(Buff::ShellOut).to receive(:shell_out).and_return(shell_out) expect { subject.git('foo') }.to raise_error(GitCommandError) end end end end