BigW Consortium Gitlab

loader_spec.rb 1.02 KB
Newer Older
1 2
require 'spec_helper'

3 4
describe Gitlab::Ci::Config::Loader do
  let(:loader) { described_class.new(yml) }
5 6 7 8 9 10

  context 'when yaml syntax is correct' do
    let(:yml) { 'image: ruby:2.2' }

    describe '#valid?' do
      it 'returns true' do
11
        expect(loader.valid?).to be true
12 13 14
      end
    end

15
    describe '#load!' do
16
      it 'returns a valid hash' do
17
        expect(loader.load!).to eq(image: 'ruby:2.2')
18 19 20 21 22 23 24 25 26
      end
    end
  end

  context 'when yaml syntax is incorrect' do
    let(:yml) { '// incorrect' }

    describe '#valid?' do
      it 'returns false' do
27
        expect(loader.valid?).to be false
28 29 30
      end
    end

31
    describe '#load!' do
32
      it 'raises error' do
33
        expect { loader.load! }.to raise_error(
34
          Gitlab::Ci::Config::Loader::FormatError,
35 36 37 38 39 40 41 42 43 44 45
          'Invalid configuration format'
        )
      end
    end
  end

  context 'when yaml config is empty' do
    let(:yml) { '' }

    describe '#valid?' do
      it 'returns false' do
46
        expect(loader.valid?).to be false
47 48 49 50
      end
    end
  end
end