diff options
author | Rémy Coutable <remy@rymai.me> | 2016-06-07 19:05:26 +0300 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2016-06-07 19:05:26 +0300 |
commit | be78a556d9be2a553cffc68937d3ce50c15e5b9c (patch) | |
tree | 2925bd389bd710426356d03a0cbfe3d47b35a3e9 /spec | |
parent | 5b83abcc01bd4a24268126dc52019b9f11152a7c (diff) | |
parent | 5ef104df59211b022ed42e38e1cdbe950ff54388 (diff) |
Merge branch 'refactor/ci-config-add-facade' into 'master'
Add new GitLab CI configuration facade class
## What does this MR do?
This MR is a first iteration of major CI configuration refactoring. See #17139 and #15060 for more details.
## What are the relevant issue numbers?
Closes #17139
See merge request !4462
Diffstat (limited to 'spec')
-rw-r--r-- | spec/lib/gitlab/ci/config/loader_spec.rb | 50 | ||||
-rw-r--r-- | spec/lib/gitlab/ci/config_spec.rb | 47 |
2 files changed, 97 insertions, 0 deletions
diff --git a/spec/lib/gitlab/ci/config/loader_spec.rb b/spec/lib/gitlab/ci/config/loader_spec.rb new file mode 100644 index 00000000000..2d44b1f60f1 --- /dev/null +++ b/spec/lib/gitlab/ci/config/loader_spec.rb @@ -0,0 +1,50 @@ +require 'spec_helper' + +describe Gitlab::Ci::Config::Loader do + let(:loader) { described_class.new(yml) } + + context 'when yaml syntax is correct' do + let(:yml) { 'image: ruby:2.2' } + + describe '#valid?' do + it 'returns true' do + expect(loader.valid?).to be true + end + end + + describe '#load!' do + it 'returns a valid hash' do + expect(loader.load!).to eq(image: 'ruby:2.2') + end + end + end + + context 'when yaml syntax is incorrect' do + let(:yml) { '// incorrect' } + + describe '#valid?' do + it 'returns false' do + expect(loader.valid?).to be false + end + end + + describe '#load!' do + it 'raises error' do + expect { loader.load! }.to raise_error( + Gitlab::Ci::Config::Loader::FormatError, + 'Invalid configuration format' + ) + end + end + end + + context 'when yaml config is empty' do + let(:yml) { '' } + + describe '#valid?' do + it 'returns false' do + expect(loader.valid?).to be false + end + end + end +end diff --git a/spec/lib/gitlab/ci/config_spec.rb b/spec/lib/gitlab/ci/config_spec.rb new file mode 100644 index 00000000000..4d46abe520f --- /dev/null +++ b/spec/lib/gitlab/ci/config_spec.rb @@ -0,0 +1,47 @@ +require 'spec_helper' + +describe Gitlab::Ci::Config do + let(:config) do + described_class.new(yml) + end + + context 'when config is valid' do + let(:yml) do + <<-EOS + image: ruby:2.2 + + rspec: + script: + - gem install rspec + - rspec + EOS + end + + describe '#to_hash' do + it 'returns hash created from string' do + hash = { + image: 'ruby:2.2', + rspec: { + script: ['gem install rspec', + 'rspec'] + } + } + + expect(config.to_hash).to eq hash + end + end + + context 'when config is invalid' do + let(:yml) { '// invalid' } + + describe '.new' do + it 'raises error' do + expect { config }.to raise_error( + Gitlab::Ci::Config::Loader::FormatError, + /Invalid configuration format/ + ) + end + end + end + end +end |