summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/ci/config/entry/files_spec.rb
blob: 6a101d80c7d1d267792254e4be2c378311565e60 (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
# frozen_string_literal: true

require 'spec_helper'

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

  describe 'validations' do
    context 'when entry config value is valid' do
      let(:config) { ['some/file', 'some/path/'] }

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

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

    describe '#errors' do
      context 'when entry value is not an array' do
        let(:config) { 'string' }

        it 'saves errors' do
          expect(entry.errors)
            .to include 'files config should be an array of strings'
        end
      end

      context 'when entry value is not an array of strings' do
        let(:config) { [1] }

        it 'saves errors' do
          expect(entry.errors)
            .to include 'files config should be an array of strings'
        end
      end

      context 'when entry value contains more than two values' do
        let(:config) { %w[file1 file2 file3] }

        it 'saves errors' do
          expect(entry.errors)
            .to include 'files config has too many items (maximum is 2)'
        end
      end
    end
  end
end