Sha256: 4958aa444a654c95035d20db5b16420df175bac175113c67a53b7e31b24f003f

Contents?: true

Size: 1.92 KB

Versions: 3

Compression:

Stored size: 1.92 KB

Contents

require 'spec_helper'
require 'r10k/git'

describe R10K::Git::Ref do

  let(:ref) { 'master' }
  let(:repo) { double('git repository') }
  subject { described_class.new(ref) }

  describe "fetching the SHA1" do
    it "raises an error if there is not a linked repository" do
      expect {
        subject.sha1
      }.to raise_error(ArgumentError, /Cannot resolve .*#{ref}.*: no associated git repository/)
    end

    it "raises an error if the SHA1 could not be resolved" do
      subject.repository = repo
      expect(repo).to receive(:rev_parse).with(ref).and_raise(R10K::Git::UnresolvableRefError, "Couldn't resolve")

      expect {
        subject.sha1
      }.to raise_error(R10K::Git::UnresolvableRefError)
    end

    it "looks up the ref against the linked repository" do
      subject.repository = repo
      expect(repo).to receive(:rev_parse).with(ref).and_return 'hash'
      expect(subject.sha1).to eq 'hash'
    end

    it "invokes the #ref method" do
      subject.repository = repo
      expect(repo).to receive(:rev_parse).with(ref).and_return 'hash'
      expect(subject).to receive(:ref).and_return ref
      expect(subject.sha1).to eq 'hash'
    end
  end

  describe "determining if the ref can be resolved" do
    describe "and the ref is a head" do
      it "is always false"
    end

    describe "and the ref is a tag" do
      it "is true if the tag has been fetched"
      it "is false if the tag cannot be resolved"
    end

    describe "and the ref is a commit" do
      it "is true if the commit has been fetched"
      it "is false if the commit cannot be resolved"
    end
  end

  describe "determining if the ref needs to be fetched" do
    it "uses the result of #resolvable? if the ref is a tag"
    it "uses the result of #resolvable? if the ref is a commit"

    it "is true if the ref is a head"
  end

  it "can be converted to a string" do
    expect(subject.to_s).to eq ref
  end

  it_behaves_like "a git ref"
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
r10k-1.4.2 spec/unit/git/ref_spec.rb
r10k-1.4.1 spec/unit/git/ref_spec.rb
r10k-1.4.0 spec/unit/git/ref_spec.rb