diff options
author | Leandro Camargo <leandroico@gmail.com> | 2016-11-21 02:38:03 -0200 |
---|---|---|
committer | Leandro Camargo <leandroico@gmail.com> | 2017-01-25 01:07:44 -0200 |
commit | 0713a7c3a9eb1bcfdf6adde0c3365549c19a3ee1 (patch) | |
tree | dc6ed374e79782124c4c6cd8ba745883e3fbb2e5 /spec/lib | |
parent | 94eb2f47c732dc9485aba4ebe52238e882a43473 (diff) | |
download | gitlab-ce-0713a7c3a9eb1bcfdf6adde0c3365549c19a3ee1.tar.gz |
Add specs to cover the implemented feature and fix a small bug
Diffstat (limited to 'spec/lib')
-rw-r--r-- | spec/lib/ci/gitlab_ci_yaml_processor_spec.rb | 31 | ||||
-rw-r--r-- | spec/lib/gitlab/ci/config/entry/coverage_spec.rb | 40 | ||||
-rw-r--r-- | spec/lib/gitlab/ci/config/entry/global_spec.rb | 17 | ||||
-rw-r--r-- | spec/lib/gitlab/ci/config/entry/job_spec.rb | 14 |
4 files changed, 97 insertions, 5 deletions
diff --git a/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb b/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb index f824e2e1efe..eb2d9c6e0e3 100644 --- a/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb +++ b/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb @@ -4,6 +4,37 @@ module Ci describe GitlabCiYamlProcessor, lib: true do let(:path) { 'path' } + describe '#build_attributes' do + context 'Coverage entry' do + subject { described_class.new(config, path).build_attributes(:rspec) } + + let(:config_base) { { rspec: { script: "rspec" } } } + let(:config) { YAML.dump(config_base) } + + context 'when config has coverage set at the global scope' do + before do + config_base.update( + coverage: { output_filter: '\(\d+\.\d+\) covered' } + ) + end + + context 'and \'rspec\' job doesn\'t have coverage set' do + it { is_expected.to include(coverage_regex: '\(\d+\.\d+\) covered') } + end + + context 'but \'rspec\' job also has coverage set' do + before do + config_base[:rspec].update( + coverage: { output_filter: '/Code coverage: \d+\.\d+/' } + ) + end + + it { is_expected.to include(coverage_regex: 'Code coverage: \d+\.\d+') } + end + end + end + end + describe "#builds_for_ref" do let(:type) { 'test' } diff --git a/spec/lib/gitlab/ci/config/entry/coverage_spec.rb b/spec/lib/gitlab/ci/config/entry/coverage_spec.rb new file mode 100644 index 00000000000..9e59755d9f8 --- /dev/null +++ b/spec/lib/gitlab/ci/config/entry/coverage_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe Gitlab::Ci::Config::Entry::Coverage do + let(:entry) { described_class.new(config) } + + describe 'validations' do + context 'when entry config value is correct' do + let(:config) { { output_filter: 'Code coverage: \d+\.\d+' } } + + describe '#value' do + subject { entry.value } + it { is_expected.to eq config } + end + + describe '#errors' do + subject { entry.errors } + it { is_expected.to be_empty } + end + + describe '#valid?' do + subject { entry } + it { is_expected.to be_valid } + end + end + + context 'when entry value is not correct' do + let(:config) { { output_filter: '(malformed regexp' } } + + describe '#errors' do + subject { entry.errors } + it { is_expected.to include /coverage output filter must be a regular expression/ } + end + + describe '#valid?' do + subject { entry } + it { is_expected.not_to be_valid } + end + end + end +end diff --git a/spec/lib/gitlab/ci/config/entry/global_spec.rb b/spec/lib/gitlab/ci/config/entry/global_spec.rb index e64c8d46bd8..66a1380bc61 100644 --- a/spec/lib/gitlab/ci/config/entry/global_spec.rb +++ b/spec/lib/gitlab/ci/config/entry/global_spec.rb @@ -4,12 +4,19 @@ describe Gitlab::Ci::Config::Entry::Global do let(:global) { described_class.new(hash) } describe '.nodes' do - it 'can contain global config keys' do - expect(described_class.nodes).to include :before_script - end + subject { described_class.nodes } + + it { is_expected.to be_a Hash } + + context 'when filtering all the entry/node names' do + subject { described_class.nodes.keys } + + let(:result) do + %i[before_script image services after_script variables stages types + cache coverage] + end - it 'returns a hash' do - expect(described_class.nodes).to be_a Hash + it { is_expected.to match_array result } end end diff --git a/spec/lib/gitlab/ci/config/entry/job_spec.rb b/spec/lib/gitlab/ci/config/entry/job_spec.rb index fc9b8b86dc4..d20f4ec207d 100644 --- a/spec/lib/gitlab/ci/config/entry/job_spec.rb +++ b/spec/lib/gitlab/ci/config/entry/job_spec.rb @@ -3,6 +3,20 @@ require 'spec_helper' describe Gitlab::Ci::Config::Entry::Job do let(:entry) { described_class.new(config, name: :rspec) } + describe '.nodes' do + context 'when filtering all the entry/node names' do + subject { described_class.nodes.keys } + + let(:result) do + %i[before_script script stage type after_script cache + image services only except variables artifacts + environment coverage] + end + + it { is_expected.to match_array result } + end + end + describe 'validations' do before { entry.compose! } |