Sha256: bb6f8b148be2484c70131c625954e72c6c13c6ef0df7713684d6f2ae65c6373b

Contents?: true

Size: 1.9 KB

Versions: 14

Compression:

Stored size: 1.9 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)

      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

14 entries across 14 versions & 1 rubygems

Version Path
r10k-1.3.5 spec/unit/git/ref_spec.rb
r10k-1.3.4 spec/unit/git/ref_spec.rb
r10k-1.2.4 spec/unit/git/ref_spec.rb
r10k-1.3.3 spec/unit/git/ref_spec.rb
r10k-1.3.2 spec/unit/git/ref_spec.rb
r10k-1.2.3 spec/unit/git/ref_spec.rb
r10k-1.3.1 spec/unit/git/ref_spec.rb
r10k-1.2.2 spec/unit/git/ref_spec.rb
r10k-1.3.0 spec/unit/git/ref_spec.rb
r10k-1.3.0rc1 spec/unit/git/ref_spec.rb
r10k-1.2.1 spec/unit/git/ref_spec.rb
r10k-1.2.0 spec/unit/git/ref_spec.rb
r10k-1.2.0rc2 spec/unit/git/ref_spec.rb
r10k-1.2.0rc1 spec/unit/git/ref_spec.rb