jobs_spec.rb 2.39 KB
Newer Older
1 2 3
require 'spec_helper'

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

  describe 'validations' do
7
    before { entry.compose! }
8

9 10 11 12 13 14 15 16 17 18 19
    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
20 21 22
      describe '#errors' do
        context 'incorrect config value type' do
          let(:config) { ['incorrect'] }
23

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

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

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

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

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

50 51
  context 'when valid job entries composed' do
    before { entry.compose! }
52 53 54

    let(:config) do
      { rspec: { script: 'rspec' },
55 56
        spinach: { script: 'spinach' },
        '.hidden'.to_sym => {} }
57 58
    end

59 60
    describe '#value' do
      it 'returns key value' do
61 62 63
        expect(entry.value).to eq(
          rspec: { name: :rspec,
                   script: %w[rspec],
64
                   commands: 'rspec',
65 66 67
                   stage: 'test' },
          spinach: { name: :spinach,
                     script: %w[spinach],
68
                     commands: 'spinach',
69
                     stage: 'test' })
70 71 72
      end
    end

73 74 75 76 77 78
    describe '#descendants' do
      it 'creates valid descendant nodes' do
        expect(entry.descendants.count).to eq 3
        expect(entry.descendants.first(2))
          .to all(be_an_instance_of(Gitlab::Ci::Config::Node::Job))
        expect(entry.descendants.last)
79
          .to be_an_instance_of(Gitlab::Ci::Config::Node::Hidden)
80 81 82 83 84 85 86
      end
    end

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