blob: c255d6e9dd6ecc8d0763db0af46cf31981ed3cda (
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
# frozen_string_literal: true
require 'fast_spec_helper'
RSpec.describe Gitlab::Ci::Config::Entry::Include::Rules do
let(:factory) do
Gitlab::Config::Entry::Factory.new(described_class)
.value(config)
end
subject(:entry) { factory.create! }
describe '.new' do
shared_examples 'a valid config' do
it { is_expected.to be_valid }
context 'when composed' do
before do
entry.compose!
end
it { is_expected.to be_valid }
end
end
shared_examples 'an invalid config' do |error_message|
it { is_expected.not_to be_valid }
it 'has errors' do
expect(entry.errors).to include(error_message)
end
end
context 'with an "if"' do
let(:config) do
[{ if: '$THIS == "that"' }]
end
it_behaves_like 'a valid config'
end
context 'with a "changes"' do
let(:config) do
[{ changes: ['filename.txt'] }]
end
context 'when composed' do
before do
entry.compose!
end
it_behaves_like 'an invalid config', /contains unknown keys: changes/
end
end
context 'with a list of two rules' do
let(:config) do
[
{ if: '$THIS == "that"' },
{ if: '$SKIP' }
]
end
it_behaves_like 'a valid config'
end
context 'without an array' do
let(:config) do
{ if: '$SKIP' }
end
it_behaves_like 'an invalid config', /should be a array/
end
end
describe '#value' do
subject(:value) { entry.value }
context 'with an "if"' do
let(:config) do
[{ if: '$THIS == "that"' }]
end
it { is_expected.to eq(config) }
end
context 'with a list of two rules' do
let(:config) do
[
{ if: '$THIS == "that"' },
{ if: '$SKIP' }
]
end
it { is_expected.to eq(config) }
end
end
end
|