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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
84c708c3
Commit
84c708c3
authored
Oct 28, 2020
by
drew cimino
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Restructure spec around method contexts
parent
51d6fab3
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
35 additions
and
39 deletions
+35
-39
spec/lib/gitlab/badge/coverage/report_spec.rb
spec/lib/gitlab/badge/coverage/report_spec.rb
+35
-39
No files found.
spec/lib/gitlab/badge/coverage/report_spec.rb
View file @
84c708c3
...
...
@@ -3,25 +3,16 @@
require
'spec_helper'
RSpec
.
describe
Gitlab
::
Badge
::
Coverage
::
Report
do
let
(
:project
)
{
double
(
'project'
)
}
let_it_be
(
:successful_pipeline
)
do
create
(
:ci_pipeline
,
:success
)
end
let
(
:project
)
{
build
(
:project
)
}
let
(
:badge
)
do
described_class
.
new
(
project
,
'master'
,
opts:
{
job:
job_name
}).
tap
do
|
new_badge
|
allow
(
new_badge
).
to
receive
(
:pipeline
).
and_return
(
successful_pipeline
)
end
described_class
.
new
(
project
,
'master'
,
opts:
{
job:
job_name
})
end
let
(
:pipeline
)
{
nil
}
let
(
:job_name
)
{
nil
}
let
(
:builds
)
{
[]
}
before
do
allow
(
successful_pipeline
).
to
receive
(
:builds
).
and_return
(
Ci
::
Build
.
where
(
id:
builds
.
map
(
&
:id
)))
end
describe
'#entity'
do
it
'describes a coverage'
do
expect
(
badge
.
entity
).
to
eq
'coverage'
...
...
@@ -40,50 +31,55 @@ RSpec.describe Gitlab::Badge::Coverage::Report do
end
end
shared_examples
'unknown coverage report'
do
context
'particular job specified'
do
let
(
:job_name
)
{
''
}
describe
'#status'
do
before
do
allow
(
badge
).
to
receive
(
:pipeline
).
and_return
(
pipeline
)
end
context
'with no pipeline'
do
it
'returns nil'
do
expect
(
badge
.
status
).
to
be_nil
end
end
context
'
particular job not
specified'
do
let
(
:
job_name
)
{
nil
}
context
'
with no job
specified'
do
let
(
:
pipeline
)
{
double
(
'pipeline'
,
coverage:
1
)
}
it
'returns
nil
'
do
expect
(
badge
.
status
).
to
be_nil
it
'returns
the pipeline coverage value
'
do
expect
(
badge
.
status
).
to
eq
(
1.00
)
end
end
end
context
'when latest successful pipeline exists'
do
let
(
:builds
)
do
[
create
(
:ci_build
,
:success
,
pipeline:
pipeline
,
name:
'first'
,
coverage:
40
),
create
(
:ci_build
,
:success
,
pipeline:
pipeline
,
coverage:
60
)
]
end
context
'with an unmatching job name specified'
do
let
(
:job_name
)
{
'incorrect name'
}
let
(
:pipeline
)
{
create
(
:ci_pipeline
,
:success
,
builds:
builds
)
}
context
'when particular job specified'
do
let
(
:job_name
)
{
'first'
}
let
(
:builds
)
do
[
create
(
:ci_build
,
:success
,
name:
'first'
,
coverage:
40
),
create
(
:ci_build
,
:success
,
coverage:
60
)
]
end
it
'returns
coverage for the particular job
'
do
expect
(
badge
.
status
).
to
eq
40
it
'returns
nil
'
do
expect
(
badge
.
status
).
to
eq
(
nil
)
end
end
context
'when particular job not specified'
do
let
(
:job_name
)
{
''
}
context
'with a matching job name specified'
do
let
(
:job_name
)
{
'first'
}
let
(
:pipeline
)
{
create
(
:ci_pipeline
,
:success
,
builds:
builds
)
}
it
'returns arithemetic mean for the pipeline'
do
expect
(
badge
.
status
).
to
eq
50
let
(
:builds
)
do
[
create
(
:ci_build
,
:success
,
name:
'first'
,
coverage:
40
),
create
(
:ci_build
,
:success
,
coverage:
60
)
]
end
end
end
context
'pipeline does not exist'
do
it_behaves_like
'unknown coverage report'
it
'returns nil'
do
expect
(
badge
.
status
).
to
eq
(
40.00
)
end
end
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