summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/ci/config/entry/key_spec.rb
blob: 327607e226647a275db0dc26aea6dd90666c031b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# frozen_string_literal: true

require 'spec_helper'

describe Gitlab::Ci::Config::Entry::Key do
  let(:entry) { described_class.new(config) }

  describe 'validations' do
    it_behaves_like 'key entry validations', 'simple key'

    context 'when entry config value is correct' do
      context 'when key is a hash' do
        let(:config) { { files: ['test'], prefix: 'something' } }

        describe '#value' do
          it 'returns key value' do
            expect(entry.value).to match(config)
          end
        end

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

      context 'when key is a symbol' do
        let(:config) { :key }

        describe '#value' do
          it 'returns key value' do
            expect(entry.value).to eq(config.to_s)
          end
        end

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

    context 'when entry value is not correct' do
      let(:config) { ['incorrect'] }

      describe '#errors' do
        it 'saves errors' do
          expect(entry.errors.first)
            .to match /should be a hash, a string or a symbol/
        end
      end
    end
  end

  describe '.default' do
    it 'returns default key' do
      expect(described_class.default).to eq 'default'
    end
  end
end