diff options
author | Wolphin <wolphin@wolph.in> | 2019-06-05 08:25:55 +0000 |
---|---|---|
committer | Kamil TrzciĆski <ayufan@ayufan.eu> | 2019-06-05 08:25:55 +0000 |
commit | 1f2244f16bc2990000a77911520b0c06095522c2 (patch) | |
tree | 1e920c31d012cb4f928397b467739e0499de83ea /spec/lib | |
parent | df549eb28c83b27500619ccb14c201a4ff87daa3 (diff) | |
download | gitlab-ce-1f2244f16bc2990000a77911520b0c06095522c2.tar.gz |
Add multiple extends support
Diffstat (limited to 'spec/lib')
-rw-r--r-- | spec/lib/gitlab/ci/config/entry/job_spec.rb | 2 | ||||
-rw-r--r-- | spec/lib/gitlab/ci/config/extendable/entry_spec.rb | 46 | ||||
-rw-r--r-- | spec/lib/gitlab/ci/yaml_processor_spec.rb | 2 |
3 files changed, 39 insertions, 11 deletions
diff --git a/spec/lib/gitlab/ci/config/entry/job_spec.rb b/spec/lib/gitlab/ci/config/entry/job_spec.rb index 0560eb42e4d..e0552ae8c57 100644 --- a/spec/lib/gitlab/ci/config/entry/job_spec.rb +++ b/spec/lib/gitlab/ci/config/entry/job_spec.rb @@ -94,7 +94,7 @@ describe Gitlab::Ci::Config::Entry::Job do it 'returns error about wrong value type' do expect(entry).not_to be_valid - expect(entry.errors).to include "job extends should be a string" + expect(entry.errors).to include "job extends should be an array of strings or a string" end end diff --git a/spec/lib/gitlab/ci/config/extendable/entry_spec.rb b/spec/lib/gitlab/ci/config/extendable/entry_spec.rb index 0a148375d11..d63612053b6 100644 --- a/spec/lib/gitlab/ci/config/extendable/entry_spec.rb +++ b/spec/lib/gitlab/ci/config/extendable/entry_spec.rb @@ -44,12 +44,12 @@ describe Gitlab::Ci::Config::Extendable::Entry do end end - describe '#extends_key' do + describe '#extends_keys' do context 'when entry is extensible' do it 'returns symbolized extends key value' do entry = described_class.new(:test, test: { extends: 'something' }) - expect(entry.extends_key).to eq :something + expect(entry.extends_keys).to eq [:something] end end @@ -57,7 +57,7 @@ describe Gitlab::Ci::Config::Extendable::Entry do it 'returns nil' do entry = described_class.new(:test, test: 'something') - expect(entry.extends_key).to be_nil + expect(entry.extends_keys).to be_nil end end end @@ -76,7 +76,7 @@ describe Gitlab::Ci::Config::Extendable::Entry do end end - describe '#base_hash!' do + describe '#base_hashes!' do subject { described_class.new(:test, hash) } context 'when base hash is not extensible' do @@ -87,8 +87,8 @@ describe Gitlab::Ci::Config::Extendable::Entry do } end - it 'returns unchanged base hash' do - expect(subject.base_hash!).to eq(script: 'rspec') + it 'returns unchanged base hashes' do + expect(subject.base_hashes!).to eq([{ script: 'rspec' }]) end end @@ -101,12 +101,12 @@ describe Gitlab::Ci::Config::Extendable::Entry do } end - it 'extends the base hash first' do - expect(subject.base_hash!).to eq(extends: 'first', script: 'rspec') + it 'extends the base hashes first' do + expect(subject.base_hashes!).to eq([{ extends: 'first', script: 'rspec' }]) end it 'mutates original context' do - subject.base_hash! + subject.base_hashes! expect(hash.fetch(:second)).to eq(extends: 'first', script: 'rspec') end @@ -171,6 +171,34 @@ describe Gitlab::Ci::Config::Extendable::Entry do end end + context 'when extending multiple hashes correctly' do + let(:hash) do + { + first: { script: 'my value', image: 'ubuntu' }, + second: { image: 'alpine' }, + test: { extends: %w(first second) } + } + end + + let(:result) do + { + first: { script: 'my value', image: 'ubuntu' }, + second: { image: 'alpine' }, + test: { extends: %w(first second), script: 'my value', image: 'alpine' } + } + end + + it 'returns extended part of the hash' do + expect(subject.extend!).to eq result[:test] + end + + it 'mutates original context' do + subject.extend! + + expect(hash).to eq result + end + end + context 'when hash is not extensible' do let(:hash) do { diff --git a/spec/lib/gitlab/ci/yaml_processor_spec.rb b/spec/lib/gitlab/ci/yaml_processor_spec.rb index 29276d5b686..635b4e556e8 100644 --- a/spec/lib/gitlab/ci/yaml_processor_spec.rb +++ b/spec/lib/gitlab/ci/yaml_processor_spec.rb @@ -1470,7 +1470,7 @@ module Gitlab expect { Gitlab::Ci::YamlProcessor.new(config) } .to raise_error(Gitlab::Ci::YamlProcessor::ValidationError, - 'rspec: unknown key in `extends`') + 'rspec: unknown keys in `extends` (something)') end end |