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
0713a7c3
Commit
0713a7c3
authored
Nov 21, 2016
by
Leandro Camargo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add specs to cover the implemented feature and fix a small bug
parent
94eb2f47
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
131 additions
and
6 deletions
+131
-6
lib/gitlab/ci/config/entry/coverage.rb
lib/gitlab/ci/config/entry/coverage.rb
+1
-1
spec/lib/ci/gitlab_ci_yaml_processor_spec.rb
spec/lib/ci/gitlab_ci_yaml_processor_spec.rb
+31
-0
spec/lib/gitlab/ci/config/entry/coverage_spec.rb
spec/lib/gitlab/ci/config/entry/coverage_spec.rb
+40
-0
spec/lib/gitlab/ci/config/entry/global_spec.rb
spec/lib/gitlab/ci/config/entry/global_spec.rb
+12
-5
spec/lib/gitlab/ci/config/entry/job_spec.rb
spec/lib/gitlab/ci/config/entry/job_spec.rb
+14
-0
spec/models/ci/build_spec.rb
spec/models/ci/build_spec.rb
+33
-0
No files found.
lib/gitlab/ci/config/entry/coverage.rb
View file @
0713a7c3
...
...
@@ -22,7 +22,7 @@ module Gitlab
if
output_filter_value
.
start_with?
(
'/'
)
&&
output_filter_value
.
end_with?
(
'/'
)
output_filter_value
[
1
...-
1
]
else
value
[
:output_filter
]
@config
[
:output_filter
]
end
end
...
...
spec/lib/ci/gitlab_ci_yaml_processor_spec.rb
View file @
0713a7c3
...
...
@@ -4,6 +4,37 @@ module Ci
describe
GitlabCiYamlProcessor
,
lib:
true
do
let
(
:path
)
{
'path'
}
describe
'#build_attributes'
do
context
'Coverage entry'
do
subject
{
described_class
.
new
(
config
,
path
).
build_attributes
(
:rspec
)
}
let
(
:config_base
)
{
{
rspec:
{
script:
"rspec"
}
}
}
let
(
:config
)
{
YAML
.
dump
(
config_base
)
}
context
'when config has coverage set at the global scope'
do
before
do
config_base
.
update
(
coverage:
{
output_filter:
'\(\d+\.\d+\) covered'
}
)
end
context
'and \'rspec\' job doesn\'t have coverage set'
do
it
{
is_expected
.
to
include
(
coverage_regex:
'\(\d+\.\d+\) covered'
)
}
end
context
'but \'rspec\' job also has coverage set'
do
before
do
config_base
[
:rspec
].
update
(
coverage:
{
output_filter:
'/Code coverage: \d+\.\d+/'
}
)
end
it
{
is_expected
.
to
include
(
coverage_regex:
'Code coverage: \d+\.\d+'
)
}
end
end
end
end
describe
"#builds_for_ref"
do
let
(
:type
)
{
'test'
}
...
...
spec/lib/gitlab/ci/config/entry/coverage_spec.rb
0 → 100644
View file @
0713a7c3
require
'spec_helper'
describe
Gitlab
::
Ci
::
Config
::
Entry
::
Coverage
do
let
(
:entry
)
{
described_class
.
new
(
config
)
}
describe
'validations'
do
context
'when entry config value is correct'
do
let
(
:config
)
{
{
output_filter:
'Code coverage: \d+\.\d+'
}
}
describe
'#value'
do
subject
{
entry
.
value
}
it
{
is_expected
.
to
eq
config
}
end
describe
'#errors'
do
subject
{
entry
.
errors
}
it
{
is_expected
.
to
be_empty
}
end
describe
'#valid?'
do
subject
{
entry
}
it
{
is_expected
.
to
be_valid
}
end
end
context
'when entry value is not correct'
do
let
(
:config
)
{
{
output_filter:
'(malformed regexp'
}
}
describe
'#errors'
do
subject
{
entry
.
errors
}
it
{
is_expected
.
to
include
/coverage output filter must be a regular expression/
}
end
describe
'#valid?'
do
subject
{
entry
}
it
{
is_expected
.
not_to
be_valid
}
end
end
end
end
spec/lib/gitlab/ci/config/entry/global_spec.rb
View file @
0713a7c3
...
...
@@ -4,12 +4,19 @@ describe Gitlab::Ci::Config::Entry::Global do
let
(
:global
)
{
described_class
.
new
(
hash
)
}
describe
'.nodes'
do
it
'can contain global config keys'
do
expect
(
described_class
.
nodes
).
to
include
:before_script
end
subject
{
described_class
.
nodes
}
it
{
is_expected
.
to
be_a
Hash
}
context
'when filtering all the entry/node names'
do
subject
{
described_class
.
nodes
.
keys
}
let
(
:result
)
do
%i[before_script image services after_script variables stages types
cache coverage]
end
it
'returns a hash'
do
expect
(
described_class
.
nodes
).
to
be_a
Hash
it
{
is_expected
.
to
match_array
result
}
end
end
...
...
spec/lib/gitlab/ci/config/entry/job_spec.rb
View file @
0713a7c3
...
...
@@ -3,6 +3,20 @@ require 'spec_helper'
describe
Gitlab
::
Ci
::
Config
::
Entry
::
Job
do
let
(
:entry
)
{
described_class
.
new
(
config
,
name: :rspec
)
}
describe
'.nodes'
do
context
'when filtering all the entry/node names'
do
subject
{
described_class
.
nodes
.
keys
}
let
(
:result
)
do
%i[before_script script stage type after_script cache
image services only except variables artifacts
environment coverage]
end
it
{
is_expected
.
to
match_array
result
}
end
end
describe
'validations'
do
before
{
entry
.
compose!
}
...
...
spec/models/ci/build_spec.rb
View file @
0713a7c3
...
...
@@ -221,6 +221,39 @@ describe Ci::Build, :models do
end
end
describe
'#coverage_regex'
do
subject
{
build
.
coverage_regex
}
let
(
:project_regex
)
{
'\(\d+\.\d+\) covered'
}
let
(
:build_regex
)
{
'Code coverage: \d+\.\d+'
}
context
'when project has build_coverage_regex set'
do
before
{
project
.
build_coverage_regex
=
project_regex
}
context
'and coverage_regex attribute is not set'
do
it
{
is_expected
.
to
eq
(
project_regex
)
}
end
context
'but coverage_regex attribute is also set'
do
before
{
build
.
coverage_regex
=
build_regex
}
it
{
is_expected
.
to
eq
(
build_regex
)
}
end
end
context
'when neither project nor build has coverage regex set'
do
it
{
is_expected
.
to
be_nil
}
end
end
describe
'#update_coverage'
do
it
'grants coverage_regex method is called inside of it'
do
build
.
coverage_regex
=
'\(\d+.\d+\%\) covered'
allow
(
build
).
to
receive
(
:trace
)
{
'Coverage 1033 / 1051 LOC (98.29%) covered'
}
allow
(
build
).
to
receive
(
:coverage_regex
).
and_call_original
allow
(
build
).
to
receive
(
:update_attributes
).
with
(
coverage:
98.29
)
{
true
}
expect
(
build
.
update_coverage
).
to
be
true
end
end
describe
'deployment'
do
describe
'#last_deployment'
do
subject
{
build
.
last_deployment
}
...
...
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