BigW Consortium Gitlab

jobs_spec.rb 2.49 KB
Newer Older
1 2
require 'spec_helper'

3
describe Gitlab::Ci::Config::Entry::Jobs do
4
  let(:entry) { described_class.new(config) }
5 6

  describe 'validations' do
7 8 9
    before do
      entry.compose!
    end
10

11 12 13 14 15 16 17 18 19 20 21
    context 'when entry config value is correct' do
      let(:config) { { rspec: { script: 'rspec' } } }

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

    context 'when entry value is not correct' do
22 23 24
      describe '#errors' do
        context 'incorrect config value type' do
          let(:config) { ['incorrect'] }
25

26
          it 'returns error about incorrect type' do
27 28 29 30
            expect(entry.errors)
              .to include 'jobs config should be a hash'
          end
        end
31

32 33
        context 'when job is unspecified' do
          let(:config) { { rspec: nil } }
34

35 36
          it 'reports error' do
            expect(entry.errors).to include "rspec config can't be blank"
37
          end
38
        end
39

40 41
        context 'when no visible jobs present' do
          let(:config) { { '.hidden'.to_sym => { script: [] } } }
42

43 44 45
          it 'returns error about no visible jobs defined' do
            expect(entry.errors)
              .to include 'jobs config should contain at least one visible job'
46 47
          end
        end
48 49 50
      end
    end
  end
51

52
  context 'when valid job entries composed' do
53 54 55
    before do
      entry.compose!
    end
56 57 58

    let(:config) do
      { rspec: { script: 'rspec' },
59 60
        spinach: { script: 'spinach' },
        '.hidden'.to_sym => {} }
61 62
    end

63 64
    describe '#value' do
      it 'returns key value' do
65 66 67
        expect(entry.value).to eq(
          rspec: { name: :rspec,
                   script: %w[rspec],
68
                   commands: 'rspec',
69
                   ignore: false,
70 71 72
                   stage: 'test' },
          spinach: { name: :spinach,
                     script: %w[spinach],
73
                     commands: 'spinach',
74
                     ignore: false,
75
                     stage: 'test' })
76 77 78
      end
    end

79 80 81 82
    describe '#descendants' do
      it 'creates valid descendant nodes' do
        expect(entry.descendants.count).to eq 3
        expect(entry.descendants.first(2))
83
          .to all(be_an_instance_of(Gitlab::Ci::Config::Entry::Job))
84
        expect(entry.descendants.last)
85
          .to be_an_instance_of(Gitlab::Ci::Config::Entry::Hidden)
86 87 88 89 90 91 92
      end
    end

    describe '#value' do
      it 'returns value of visible jobs only' do
        expect(entry.value.keys).to eq [:rspec, :spinach]
      end
93 94
    end
  end
95
end