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

rules_spec.rb « external « config « ci « gitlab « lib « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 89ea13d710dd599d7920a5a91d073c7cca54f769 (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
# frozen_string_literal: true

require 'fast_spec_helper'

RSpec.describe Gitlab::Ci::Config::External::Rules do
  let(:rule_hashes) {}

  subject(:rules) { described_class.new(rule_hashes) }

  describe '#evaluate' do
    let(:context) { double(variables: {}) }

    subject(:result) { rules.evaluate(context).pass? }

    context 'when there is no rule' do
      it { is_expected.to eq(true) }
    end

    context 'when there is a rule' do
      let(:rule_hashes) { [{ if: '$MY_VAR == "hello"' }] }

      context 'when the rule matches' do
        let(:context) { double(variables: { MY_VAR: 'hello' }) }

        it { is_expected.to eq(true) }
      end

      context 'when the rule does not match' do
        let(:context) { double(variables: { MY_VAR: 'invalid' }) }

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