Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-10-30 18:08:59 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-10-30 18:08:59 +0300
commit038366a0932c5f88019cc3db85382f26af3933e7 (patch)
tree584aec1f4ca189f85ccd0b067f6c2e712c8fc004 /spec/lib/gitlab/badge
parent347876a78ef1cc8b630ad99b919ae0f61abbae68 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/lib/gitlab/badge')
-rw-r--r--spec/lib/gitlab/badge/coverage/report_spec.rb87
1 files changed, 31 insertions, 56 deletions
diff --git a/spec/lib/gitlab/badge/coverage/report_spec.rb b/spec/lib/gitlab/badge/coverage/report_spec.rb
index 4a9508712a4..ebe6b8603b1 100644
--- a/spec/lib/gitlab/badge/coverage/report_spec.rb
+++ b/spec/lib/gitlab/badge/coverage/report_spec.rb
@@ -3,13 +3,22 @@
require 'spec_helper'
RSpec.describe Gitlab::Badge::Coverage::Report do
- let(:project) { create(:project, :repository) }
- let(:job_name) { nil }
+ let_it_be(:project) { create(:project) }
+ let_it_be(:pipeline) { create(:ci_pipeline, :success, project: project) }
+
+ let_it_be(:builds) do
+ [
+ create(:ci_build, :success, pipeline: pipeline, coverage: 40, name: 'first'),
+ create(:ci_build, :success, pipeline: pipeline, coverage: 60)
+ ]
+ end
let(:badge) do
described_class.new(project, 'master', opts: { job: job_name })
end
+ let(:job_name) { nil }
+
describe '#entity' do
it 'describes a coverage' do
expect(badge.entity).to eq 'coverage'
@@ -28,81 +37,47 @@ RSpec.describe Gitlab::Badge::Coverage::Report do
end
end
- shared_examples 'unknown coverage report' do
- context 'particular job specified' do
- let(:job_name) { '' }
-
- it 'returns nil' do
- expect(badge.status).to be_nil
- end
+ describe '#status' do
+ before do
+ allow(badge).to receive(:pipeline).and_return(pipeline)
end
- context 'particular job not specified' do
- let(:job_name) { nil }
+ context 'with no pipeline' do
+ let(:pipeline) { nil }
it 'returns nil' do
expect(badge.status).to be_nil
end
end
- end
-
- context 'when latest successful pipeline exists' do
- before do
- create_pipeline do |pipeline|
- create(:ci_build, :success, pipeline: pipeline, name: 'first', coverage: 40)
- create(:ci_build, :success, pipeline: pipeline, coverage: 60)
- end
-
- create_pipeline do |pipeline|
- create(:ci_build, :failed, pipeline: pipeline, coverage: 10)
- end
- end
-
- context 'when particular job specified' do
- let(:job_name) { 'first' }
- it 'returns coverage for the particular job' do
- expect(badge.status).to eq 40
+ context 'with no job specified' do
+ it 'returns the pipeline coverage value' do
+ expect(badge.status).to eq(50.00)
end
end
- context 'when particular job not specified' do
- let(:job_name) { '' }
-
- it 'returns arithemetic mean for the pipeline' do
- expect(badge.status).to eq 50
- end
- end
- end
+ context 'with a blank job name' do
+ let(:job_name) { ' ' }
- context 'when only failed pipeline exists' do
- before do
- create_pipeline do |pipeline|
- create(:ci_build, :failed, pipeline: pipeline, coverage: 10)
+ it 'returns the pipeline coverage value' do
+ expect(badge.status).to eq(50.00)
end
end
- it_behaves_like 'unknown coverage report'
+ context 'with an unmatching job name specified' do
+ let(:job_name) { 'incorrect name' }
- context 'particular job specified' do
- let(:job_name) { 'nonexistent' }
-
- it 'retruns nil' do
+ it 'returns nil' do
expect(badge.status).to be_nil
end
end
- end
- context 'pipeline does not exist' do
- it_behaves_like 'unknown coverage report'
- end
-
- def create_pipeline
- opts = { project: project, sha: project.commit.id, ref: 'master' }
+ context 'with a matching job name specified' do
+ let(:job_name) { 'first' }
- create(:ci_pipeline, opts).tap do |pipeline|
- yield pipeline
- ::Ci::ProcessPipelineService.new(pipeline).execute
+ it 'returns the pipeline coverage value' do
+ expect(badge.status).to eq(40.00)
+ end
end
end
end