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

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/lib/gitlab/ci/config/entry/include/rules_spec.rb')
-rw-r--r--spec/lib/gitlab/ci/config/entry/include/rules_spec.rb98
1 files changed, 98 insertions, 0 deletions
diff --git a/spec/lib/gitlab/ci/config/entry/include/rules_spec.rb b/spec/lib/gitlab/ci/config/entry/include/rules_spec.rb
new file mode 100644
index 00000000000..c255d6e9dd6
--- /dev/null
+++ b/spec/lib/gitlab/ci/config/entry/include/rules_spec.rb
@@ -0,0 +1,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