|
44 | 44 | end
|
45 | 45 | end
|
46 | 46 |
|
47 |
| - context 'pipeline exists' do |
48 |
| - let!(:pipeline) do |
49 |
| - create(:ci_pipeline, project: project, |
50 |
| - sha: project.commit.id, |
51 |
| - ref: 'master') |
52 |
| - end |
| 47 | + context 'when latest successful pipeline exists' do |
| 48 | + before do |
| 49 | + create_pipeline do |pipeline| |
| 50 | + create(:ci_build, :success, pipeline: pipeline, name: 'first', coverage: 40) |
| 51 | + create(:ci_build, :success, pipeline: pipeline, coverage: 60) |
| 52 | + end |
53 | 53 |
|
54 |
| - context 'builds exist' do |
55 |
| - before do |
56 |
| - create(:ci_build, name: 'first', pipeline: pipeline, coverage: 40) |
57 |
| - create(:ci_build, pipeline: pipeline, coverage: 60) |
| 54 | + create_pipeline do |pipeline| |
| 55 | + create(:ci_build, :failed, pipeline: pipeline, coverage: 10) |
58 | 56 | end
|
| 57 | + end |
59 | 58 |
|
60 |
| - context 'particular job specified' do |
61 |
| - let(:job_name) { 'first' } |
| 59 | + context 'when particular job specified' do |
| 60 | + let(:job_name) { 'first' } |
62 | 61 |
|
63 |
| - it 'returns coverage for the particular job' do |
64 |
| - expect(badge.status).to eq 40 |
65 |
| - end |
| 62 | + it 'returns coverage for the particular job' do |
| 63 | + expect(badge.status).to eq 40 |
66 | 64 | end
|
| 65 | + end |
67 | 66 |
|
68 |
| - context 'particular job not specified' do |
69 |
| - let(:job_name) { '' } |
| 67 | + context 'when particular job not specified' do |
| 68 | + let(:job_name) { '' } |
| 69 | + |
| 70 | + it 'returns arithemetic mean for the pipeline' do |
| 71 | + expect(badge.status).to eq 50 |
| 72 | + end |
| 73 | + end |
| 74 | + end |
70 | 75 |
|
71 |
| - it 'returns arithemetic mean for the pipeline' do |
72 |
| - expect(badge.status).to eq 50 |
73 |
| - end |
| 76 | + context 'when only failed pipeline exists' do |
| 77 | + before do |
| 78 | + create_pipeline do |pipeline| |
| 79 | + create(:ci_build, :failed, pipeline: pipeline, coverage: 10) |
74 | 80 | end
|
75 | 81 | end
|
76 | 82 |
|
77 |
| - context 'builds do not exist' do |
78 |
| - it_behaves_like 'unknown coverage report' |
| 83 | + it_behaves_like 'unknown coverage report' |
79 | 84 |
|
80 |
| - context 'particular job specified' do |
81 |
| - let(:job_name) { 'nonexistent' } |
| 85 | + context 'particular job specified' do |
| 86 | + let(:job_name) { 'nonexistent' } |
82 | 87 |
|
83 |
| - it 'retruns nil' do |
84 |
| - expect(badge.status).to be_nil |
85 |
| - end |
| 88 | + it 'retruns nil' do |
| 89 | + expect(badge.status).to be_nil |
86 | 90 | end
|
87 | 91 | end
|
88 | 92 | end
|
89 | 93 |
|
90 | 94 | context 'pipeline does not exist' do
|
91 | 95 | it_behaves_like 'unknown coverage report'
|
92 | 96 | end
|
| 97 | + |
| 98 | + def create_pipeline |
| 99 | + opts = { project: project, sha: project.commit.id, ref: 'master' } |
| 100 | + |
| 101 | + create(:ci_pipeline, opts).tap do |pipeline| |
| 102 | + yield pipeline |
| 103 | + pipeline.build_updated |
| 104 | + end |
| 105 | + end |
93 | 106 | end
|
0 commit comments