Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
gitlab-ce
Commits
f0ff1bfd
Commit
f0ff1bfd
authored
Aug 11, 2016
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement the main class of test coverage badge
parent
f3de46e6
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
98 additions
and
9 deletions
+98
-9
lib/gitlab/badge/coverage/report.rb
lib/gitlab/badge/coverage/report.rb
+30
-1
spec/lib/gitlab/badge/coverage/report_spec.rb
spec/lib/gitlab/badge/coverage/report_spec.rb
+68
-8
No files found.
lib/gitlab/badge/coverage/report.rb
View file @
f0ff1bfd
...
...
@@ -5,13 +5,42 @@ module Gitlab
# Test coverage report badge
#
class
Report
<
Badge
::
Base
attr_reader
:project
,
:ref
,
:job
def
initialize
(
project
,
ref
,
job
=
nil
)
@project
=
project
@ref
=
ref
@job
=
job
@pipeline
=
@project
.
pipelines
.
where
(
ref:
@ref
)
.
where
(
sha:
@project
.
commit
(
@ref
).
try
(
:sha
))
.
first
end
def
entity
'coverage'
end
def
status
@coverage
||=
raw_coverage
return
unless
@coverage
@coverage
.
to_i
end
def
coverage
private
def
raw_coverage
return
unless
@pipeline
if
@job
.
blank?
@pipeline
.
coverage
else
@pipeline
.
builds
.
find_by
(
name:
@job
)
.
try
(
:coverage
)
end
end
end
end
...
...
spec/lib/gitlab/badge/coverage/report_spec.rb
View file @
f0ff1bfd
...
...
@@ -2,20 +2,80 @@ require 'spec_helper'
describe
Gitlab
::
Badge
::
Coverage
::
Report
do
let
(
:project
)
{
create
(
:project
)
}
let
(
:job_name
)
{
nil
}
let
(
:pipeline
)
do
let
(
:badge
)
do
described_class
.
new
(
project
,
'master'
,
job_name
)
end
describe
'#entity'
do
it
'describes a coverage'
do
expect
(
badge
.
entity
).
to
eq
'coverage'
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
end
context
'particular job not specified'
do
let
(
:job_name
)
{
nil
}
it
'returns nil'
do
expect
(
badge
.
status
).
to
be_nil
end
end
end
context
'pipeline exists'
do
let!
(
:pipeline
)
do
create
(
:ci_pipeline
,
project:
project
,
sha:
project
.
commit
.
id
,
ref:
'master'
)
end
let
(
:badge
)
do
described_class
.
new
(
project
,
'master'
)
context
'builds exist'
do
before
do
create
(
:ci_build
,
name:
'first'
,
pipeline:
pipeline
,
coverage:
40
)
create
(
:ci_build
,
pipeline:
pipeline
,
coverage:
60
)
end
context
'builds exist'
do
context
'particular job specified'
do
let
(
:job_name
)
{
'first'
}
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
)
{
''
}
it
'returns arithemetic mean for the pipeline'
do
expect
(
badge
.
status
).
to
eq
50
end
end
end
context
'builds do not exist'
do
it_behaves_like
'unknown coverage report'
context
'particular job specified'
do
let
(
:job_name
)
{
'nonexistent'
}
it
'retruns nil'
do
expect
(
badge
.
status
).
to
be_nil
end
end
end
end
context
'pipeline does not exist'
do
it_behaves_like
'unknown coverage report'
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment