BigW Consortium Gitlab

factory_spec.rb 2.08 KB
Newer Older
1 2
require 'spec_helper'

3
describe Gitlab::Ci::Config::Entry::Factory do
4
  describe '#create!' do
5 6
    let(:factory) { described_class.new(entry) }
    let(:entry) { Gitlab::Ci::Config::Entry::Script }
7 8

    context 'when setting a concrete value' do
9
      it 'creates entry with valid value' do
10 11 12
        entry = factory
          .value(%w(ls pwd))
          .create!
13

Douwe Maan committed
14
        expect(entry.value).to eq %w(ls pwd)
15 16 17 18
      end

      context 'when setting description' do
        it 'creates entry with description' do
19 20 21 22
          entry = factory
            .value(%w(ls pwd))
            .with(description: 'test description')
            .create!
23

Douwe Maan committed
24
          expect(entry.value).to eq %w(ls pwd)
25 26 27
          expect(entry.description).to eq 'test description'
        end
      end
28 29 30

      context 'when setting key' do
        it 'creates entry with custom key' do
31 32 33 34
          entry = factory
            .value(%w(ls pwd))
            .with(key: 'test key')
            .create!
35 36 37 38

          expect(entry.key).to eq 'test key'
        end
      end
39 40

      context 'when setting a parent' do
41
        let(:object) { Object.new }
42 43

        it 'creates entry with valid parent' do
44 45 46 47
          entry = factory
            .value('ls')
            .with(parent: object)
            .create!
48

49
          expect(entry.parent).to eq object
50 51
        end
      end
52 53
    end

54
    context 'when not setting a value' do
55 56
      it 'raises error' do
        expect { factory.create! }.to raise_error(
57
          Gitlab::Ci::Config::Entry::Factory::InvalidFactory
58 59 60 61
        )
      end
    end

62
    context 'when creating entry with nil value' do
63
      it 'creates an unspecified entry' do
64 65 66
        entry = factory
          .value(nil)
          .create!
67

68
        expect(entry)
69
          .not_to be_specified
70 71
      end
    end
72 73

    context 'when passing metadata' do
74
      let(:entry) { spy('entry') }
75 76

      it 'passes metadata as a parameter' do
77 78 79 80
        factory
          .value('some value')
          .metadata(some: 'hash')
          .create!
81

82 83
        expect(entry).to have_received(:new)
          .with('some value', { some: 'hash' })
84 85
      end
    end
86 87
  end
end