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

build_matcher_spec.rb « matching « ci « gitlab « lib « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: f12e85da9c2f0a228cbd69ce33fa894b4b086da2 (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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# frozen_string_literal: true

require 'fast_spec_helper'

RSpec.describe Gitlab::Ci::Matching::BuildMatcher do
  let(:dummy_attributes) do
    {
      protected: true,
      tag_list: %w[tag1 tag2],
      build_ids: [1, 2, 3],
      project: :my_project
    }
  end

  subject(:matcher) { described_class.new(attributes) }

  describe '.new' do
    context 'when attributes are missing' do
      let(:attributes) { {} }

      it { expect { matcher }.to raise_error(KeyError) }
    end

    context 'with attributes' do
      let(:attributes) { dummy_attributes }

      it { expect(matcher.protected).to eq(true) }

      it { expect(matcher.tag_list).to eq(%w[tag1 tag2]) }

      it { expect(matcher.build_ids).to eq([1, 2, 3]) }

      it { expect(matcher.project).to eq(:my_project) }
    end
  end

  describe '#protected?' do
    context 'when protected is set to true' do
      let(:attributes) { dummy_attributes }

      it { expect(matcher.protected?).to be_truthy }
    end

    context 'when protected is set to false' do
      let(:attributes) { dummy_attributes.merge(protected: false) }

      it { expect(matcher.protected?).to be_falsey }
    end
  end

  describe '#has_tags?' do
    context 'when tags are present' do
      let(:attributes) { dummy_attributes }

      it { expect(matcher.has_tags?).to be_truthy }
    end

    context 'when tags are empty' do
      let(:attributes) { dummy_attributes.merge(tag_list: []) }

      it { expect(matcher.has_tags?).to be_falsey }
    end
  end
end