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:
authorGrzegorz Bizon <grzesiek.bizon@gmail.com>2016-08-18 12:37:07 +0300
committerGrzegorz Bizon <grzesiek.bizon@gmail.com>2016-08-18 17:30:43 +0300
commit42496ecef778ad6d3500babbf33d350b6ab984d7 (patch)
tree013ac8ce320ca92a86444d9603e56a56c0ba1158 /spec/lib/gitlab/badge
parentac73de508e21af95b473bfafc2ca2543b234430d (diff)
Render coverage badge for latest successful pipeline
Diffstat (limited to 'spec/lib/gitlab/badge')
-rw-r--r--spec/lib/gitlab/badge/coverage/report_spec.rb67
1 files changed, 40 insertions, 27 deletions
diff --git a/spec/lib/gitlab/badge/coverage/report_spec.rb b/spec/lib/gitlab/badge/coverage/report_spec.rb
index 1ff49602486..ab0cce6e091 100644
--- a/spec/lib/gitlab/badge/coverage/report_spec.rb
+++ b/spec/lib/gitlab/badge/coverage/report_spec.rb
@@ -44,45 +44,49 @@ describe Gitlab::Badge::Coverage::Report do
end
end
- context 'pipeline exists' do
- let!(:pipeline) do
- create(:ci_pipeline, project: project,
- sha: project.commit.id,
- ref: 'master')
- 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
- context 'builds exist' do
- before do
- create(:ci_build, name: 'first', pipeline: pipeline, coverage: 40)
- create(:ci_build, pipeline: pipeline, coverage: 60)
+ create_pipeline do |pipeline|
+ create(:ci_build, :failed, pipeline: pipeline, coverage: 10)
end
+ end
- context 'particular job specified' do
- let(:job_name) { 'first' }
+ context 'when particular job specified' do
+ let(:job_name) { 'first' }
- it 'returns coverage for the particular job' do
- expect(badge.status).to eq 40
- end
+ it 'returns coverage for the particular job' do
+ expect(badge.status).to eq 40
end
+ end
- context 'particular job not specified' do
- let(:job_name) { '' }
+ 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
- it 'returns arithemetic mean for the pipeline' do
- expect(badge.status).to eq 50
- end
+ context 'when only failed pipeline exists' do
+ before do
+ create_pipeline do |pipeline|
+ create(:ci_build, :failed, pipeline: pipeline, coverage: 10)
end
end
- context 'builds do not exist' do
- it_behaves_like 'unknown coverage report'
+ it_behaves_like 'unknown coverage report'
- context 'particular job specified' do
- let(:job_name) { 'nonexistent' }
+ context 'particular job specified' do
+ let(:job_name) { 'nonexistent' }
- it 'retruns nil' do
- expect(badge.status).to be_nil
- end
+ it 'retruns nil' do
+ expect(badge.status).to be_nil
end
end
end
@@ -90,4 +94,13 @@ describe Gitlab::Badge::Coverage::Report do
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' }
+
+ create(:ci_pipeline, opts).tap do |pipeline|
+ yield pipeline
+ pipeline.build_updated
+ end
+ end
end