summaryrefslogtreecommitdiff
path: root/spec/finders/template_finder_spec.rb
blob: ed47752cf6024c6054b24f051c30fa7a0abafa03 (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
# frozen_string_literal: true

require 'spec_helper'

describe TemplateFinder do
  using RSpec::Parameterized::TableSyntax

  describe '#build' do
    let(:project) { build_stubbed(:project) }

    where(:type, :expected_class) do
      :dockerfiles    | described_class
      :gitignores     | described_class
      :gitlab_ci_ymls | described_class
      :licenses       | ::LicenseTemplateFinder
    end

    with_them do
      subject(:finder) { described_class.build(type, project) }

      it { is_expected.to be_a(expected_class) }
      it { expect(finder.project).to eq(project) }
    end
  end

  describe '#execute' do
    where(:type, :vendored_name) do
      :dockerfiles    | 'Binary'
      :gitignores     | 'Actionscript'
      :gitlab_ci_ymls | 'Android'
    end

    with_them do
      it 'returns all vendored templates when no name is specified' do
        result = described_class.new(type, nil).execute

        expect(result).to include(have_attributes(name: vendored_name))
      end

      it 'returns only the specified vendored template when a name is specified' do
        result = described_class.new(type, nil, name: vendored_name).execute

        expect(result).to have_attributes(name: vendored_name)
      end

      it 'returns nil when an unknown name is specified' do
        result = described_class.new(type, nil, name: 'unknown').execute

        expect(result).to be_nil
      end
    end
  end
end