Sha256: dd3dda8cb5c5e05dfd99a76fb6c7fe3793103f286dd8758eca352eb0c94e0367

Contents?: true

Size: 1.99 KB

Versions: 1

Compression:

Stored size: 1.99 KB

Contents

require 'pact_broker/client/git'

module PactBroker
  module Client
    module Git
      describe ".branch" do
        before do
          allow(ENV).to receive(:[]).and_call_original
          Git::BRANCH_ENV_VAR_NAMES.each do | env_var_name |
            allow(ENV).to receive(:[]).with(env_var_name).and_return(nil)
          end
        end

        subject { Git.branch }

        context "when there is a known environment variable for the branch" do
          before do
            allow(ENV).to receive(:[]).with("BUILDKITE_BRANCH").and_return("")
            allow(ENV).to receive(:[]).with("TRAVIS_BRANCH").and_return("foo")
          end

          it "returns the value of the environment variable" do
            expect(subject).to eq "foo"
          end
        end

        context "when there is no known environment variable for the branch" do
          it "attempts to execute a git command to determine the value" do
            expect { subject }.to_not raise_error
          end
        end

        context "when the git branch name comes back as HEAD" do
          before do
            allow(Git).to receive(:execute_git_command).and_return("HEAD")
          end

          it "raises an error" do
            expect { subject }.to raise_error PactBroker::Client::Error, /returned 'HEAD'/
          end
        end

        context "when the git branch name comes back as an empty string" do
          before do
            allow(Git).to receive(:execute_git_command).and_return("")
          end

          it "raises an error" do
            expect { subject }.to raise_error PactBroker::Client::Error, /an empty string/
          end
        end

        context "when there is an error executing the git command" do
          before do
            allow(Git).to receive(:execute_git_command).and_raise("some error")
          end

          it "raises an error" do
            expect { subject }.to raise_error PactBroker::Client::Error, /some error/
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pact_broker-client-1.21.0 spec/lib/pact_broker/client/git_spec.rb