2019-10-16 05:07:51 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-08-28 09:14:39 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-16 14:09:01 -04:00
|
|
|
RSpec.describe TemplateFinder do
|
2018-08-28 09:14:39 -04:00
|
|
|
using RSpec::Parameterized::TableSyntax
|
|
|
|
|
2018-09-05 09:45:02 -04:00
|
|
|
describe '#build' do
|
2018-10-02 19:00:38 -04:00
|
|
|
let(:project) { build_stubbed(:project) }
|
|
|
|
|
2018-09-05 09:45:02 -04:00
|
|
|
where(:type, :expected_class) do
|
|
|
|
:dockerfiles | described_class
|
|
|
|
:gitignores | described_class
|
|
|
|
:gitlab_ci_ymls | described_class
|
2020-08-03 05:09:42 -04:00
|
|
|
:licenses | ::LicenseTemplateFinder
|
|
|
|
:metrics_dashboard_ymls | described_class
|
2018-09-05 09:45:02 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
with_them do
|
2018-10-02 19:00:38 -04:00
|
|
|
subject(:finder) { described_class.build(type, project) }
|
2018-09-05 09:45:02 -04:00
|
|
|
|
|
|
|
it { is_expected.to be_a(expected_class) }
|
2018-10-02 19:00:38 -04:00
|
|
|
it { expect(finder.project).to eq(project) }
|
2018-09-05 09:45:02 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-08-28 09:14:39 -04:00
|
|
|
describe '#execute' do
|
|
|
|
where(:type, :vendored_name) do
|
|
|
|
:dockerfiles | 'Binary'
|
|
|
|
:gitignores | 'Actionscript'
|
|
|
|
:gitlab_ci_ymls | 'Android'
|
2020-08-03 05:09:42 -04:00
|
|
|
:metrics_dashboard_ymls | 'Default'
|
2018-08-28 09:14:39 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
with_them do
|
|
|
|
it 'returns all vendored templates when no name is specified' do
|
2018-10-02 19:00:38 -04:00
|
|
|
result = described_class.new(type, nil).execute
|
2018-08-28 09:14:39 -04:00
|
|
|
|
|
|
|
expect(result).to include(have_attributes(name: vendored_name))
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns only the specified vendored template when a name is specified' do
|
2018-10-02 19:00:38 -04:00
|
|
|
result = described_class.new(type, nil, name: vendored_name).execute
|
2018-08-28 09:14:39 -04:00
|
|
|
|
|
|
|
expect(result).to have_attributes(name: vendored_name)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns nil when an unknown name is specified' do
|
2018-10-02 19:00:38 -04:00
|
|
|
result = described_class.new(type, nil, name: 'unknown').execute
|
2018-08-28 09:14:39 -04:00
|
|
|
|
|
|
|
expect(result).to be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|