Welcome to mirror list, hosted at ThFree Co, Russian Federation.

build_spec.rb « context « build « ci « gitlab « lib « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 7f862a3b80a78dc123eb0aabb5453e34302aaa24 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Gitlab::Ci::Build::Context::Build do
  let(:pipeline)        { create(:ci_pipeline) }
  let(:seed_attributes) { { 'name' => 'some-job' } }

  let(:context) { described_class.new(pipeline, seed_attributes) }

  shared_examples 'variables collection' do
    it { is_expected.to include('CI_COMMIT_REF_NAME' => 'master') }
    it { is_expected.to include('CI_PIPELINE_IID'    => pipeline.iid.to_s) }
    it { is_expected.to include('CI_PROJECT_PATH'    => pipeline.project.full_path) }
    it { is_expected.to include('CI_JOB_NAME'        => 'some-job') }
    it { is_expected.to include('CI_BUILD_REF_NAME'  => 'master') }

    context 'without passed build-specific attributes' do
      let(:context) { described_class.new(pipeline) }

      it { is_expected.to include('CI_JOB_NAME'       => nil) }
      it { is_expected.to include('CI_BUILD_REF_NAME' => 'master') }
      it { is_expected.to include('CI_PROJECT_PATH'   => pipeline.project.full_path) }
    end
  end

  describe '#variables' do
    subject { context.variables.to_hash }

    it { expect(context.variables).to be_instance_of(Gitlab::Ci::Variables::Collection) }

    it_behaves_like 'variables collection'
  end

  describe '#variables_hash' do
    subject { context.variables_hash }

    it { expect(context.variables_hash).to be_instance_of(ActiveSupport::HashWithIndifferentAccess) }

    it_behaves_like 'variables collection'
  end
end