summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/ci/build/rules/rule_spec.rb
blob: 99852bd4228efedcd2a37dea2ebc63af4079bfff (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
require 'spec_helper'

describe Gitlab::Ci::Build::Rules::Rule do
  let(:seed) do
    double('build seed',
      to_resource: ci_build,
      scoped_variables_hash: ci_build.scoped_variables_hash
    )
  end

  let(:pipeline) { create(:ci_pipeline) }
  let(:ci_build) { build(:ci_build, pipeline: pipeline) }
  let(:rule)     { described_class.new(rule_hash) }

  describe '#matches?' do
    subject { rule.matches?(pipeline, seed) }

    context 'with one matching clause' do
      let(:rule_hash) do
        { if: '$VAR == null', when: 'always' }
      end

      it { is_expected.to eq(true) }
    end

    context 'with two matching clauses' do
      let(:rule_hash) do
        { if: '$VAR == null', changes: '**/*', when: 'always' }
      end

      it { is_expected.to eq(true) }
    end

    context 'with a matching and non-matching clause' do
      let(:rule_hash) do
        { if: '$VAR != null', changes: '$VAR == null', when: 'always' }
      end

      it { is_expected.to eq(false) }
    end

    context 'with two non-matching clauses' do
      let(:rule_hash) do
        { if: '$VAR != null', changes: 'README', when: 'always' }
      end

      it { is_expected.to eq(false) }
    end
  end
end