debian-mirror-gitlab/spec/lib/gitlab/template/gitlab_ci_yml_template_spec.rb

69 lines
1.7 KiB
Ruby
Raw Normal View History

2019-12-04 20:38:33 +05:30
# frozen_string_literal: true
2016-06-02 11:05:42 +05:30
require 'spec_helper'
2016-09-13 17:45:13 +05:30
describe Gitlab::Template::GitlabCiYmlTemplate do
2016-06-22 15:30:34 +05:30
subject { described_class }
2016-06-02 11:05:42 +05:30
describe '.all' do
2016-09-13 17:45:13 +05:30
it 'strips the gitlab-ci suffix' do
expect(subject.all.first.name).not_to end_with('.gitlab-ci.yml')
2016-06-02 11:05:42 +05:30
end
it 'combines the globals and rest' do
all = subject.all.map(&:name)
2016-09-13 17:45:13 +05:30
expect(all).to include('Elixir')
expect(all).to include('Docker')
2016-06-02 11:05:42 +05:30
expect(all).to include('Ruby')
end
2019-09-04 21:01:54 +05:30
it 'ensure that the template name is used exactly once' do
all = subject.all.group_by(&:name)
duplicates = all.select { |_, templates| templates.length > 1 }
expect(duplicates).to be_empty
end
2016-06-02 11:05:42 +05:30
end
describe '.find' do
it 'returns nil if the file does not exist' do
expect(subject.find('mepmep-yadida')).to be nil
end
2016-09-13 17:45:13 +05:30
it 'returns the GitlabCiYml object of a valid file' do
2016-06-02 11:05:42 +05:30
ruby = subject.find('Ruby')
2017-08-17 22:00:37 +05:30
expect(ruby).to be_a described_class
2016-06-02 11:05:42 +05:30
expect(ruby.name).to eq('Ruby')
end
end
2018-03-17 18:26:18 +05:30
describe '.by_category' do
it 'returns sorted results' do
result = described_class.by_category('General')
expect(result).to eq(result.sort)
end
end
2016-06-02 11:05:42 +05:30
describe '#content' do
it 'loads the full file' do
2018-12-05 23:21:45 +05:30
gitignore = subject.new(Rails.root.join('lib/gitlab/ci/templates/Ruby.gitlab-ci.yml'))
2016-06-02 11:05:42 +05:30
expect(gitignore.name).to eq 'Ruby'
2016-09-13 17:45:13 +05:30
expect(gitignore.content).to start_with('#')
2016-06-02 11:05:42 +05:30
end
end
2018-03-17 18:26:18 +05:30
describe '#<=>' do
it 'sorts lexicographically' do
one = described_class.new('a.gitlab-ci.yml')
other = described_class.new('z.gitlab-ci.yml')
expect(one.<=>(other)).to be(-1)
expect([other, one].sort).to eq([one, other])
end
end
2016-06-02 11:05:42 +05:30
end