BigW Consortium Gitlab

config_spec.rb 1.48 KB
Newer Older
1 2 3 4 5 6 7
require 'spec_helper'

describe Gitlab::Ci::Config do
  let(:config) do
    described_class.new(yml)
  end

8
  context 'when config is valid' do
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
    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
32 33 34 35 36 37 38 39 40 41

      describe '#valid?' do
        it 'is valid' do
          expect(config).to be_valid
        end

        it 'has no errors' do
          expect(config.errors).to be_empty
        end
      end
42
    end
43 44

    context 'when config is invalid' do
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
      context 'when yml is incorrect' 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

      context 'when config logic is incorrect' do
        let(:yml) { 'before_script: "ls"' }

        describe '#valid?' do
          it 'is not valid' do
            expect(config).not_to be_valid
          end

          it 'has errors' do
            expect(config.errors).not_to be_empty
          end
69 70 71
        end
      end
    end
72 73
  end
end