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
5b3dbbad
Commit
5b3dbbad
authored
Apr 02, 2020
by
Maxime Orefice
Committed by
charlie ablett
Apr 02, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor TestCase initialization
parent
00286b2f
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
31 additions
and
61 deletions
+31
-61
lib/gitlab/ci/reports/test_case.rb
lib/gitlab/ci/reports/test_case.rb
+11
-12
spec/factories/ci/test_case.rb
spec/factories/ci/test_case.rb
+4
-3
spec/lib/gitlab/ci/reports/test_case_spec.rb
spec/lib/gitlab/ci/reports/test_case_spec.rb
+16
-46
No files found.
lib/gitlab/ci/reports/test_case.rb
View file @
5b3dbbad
...
...
@@ -12,20 +12,19 @@ module Gitlab
attr_reader
:name
,
:classname
,
:execution_time
,
:status
,
:file
,
:system_output
,
:stack_trace
,
:key
,
:attachment
,
:job
# rubocop: disable Metrics/ParameterLists
def
initialize
(
name
:,
classname
:,
execution_time
:,
status
:,
file:
nil
,
system_output:
nil
,
stack_trace:
nil
,
attachment:
nil
,
job:
nil
)
@name
=
name
@classname
=
classname
@file
=
file
@execution_time
=
execution_time
.
to_f
@status
=
status
@system_output
=
system_output
@stack_trace
=
stack_trace
def
initialize
(
params
)
@name
=
params
.
fetch
(
:name
)
@classname
=
params
.
fetch
(
:classname
)
@file
=
params
.
fetch
(
:file
,
nil
)
@execution_time
=
params
.
fetch
(
:execution_time
).
to_f
@status
=
params
.
fetch
(
:status
)
@system_output
=
params
.
fetch
(
:system_output
,
nil
)
@stack_trace
=
params
.
fetch
(
:stack_trace
,
nil
)
@attachment
=
params
.
fetch
(
:attachment
,
nil
)
@job
=
params
.
fetch
(
:job
,
nil
)
@key
=
sanitize_key_name
(
"
#{
classname
}
_
#{
name
}
"
)
@attachment
=
attachment
@job
=
job
end
# rubocop: enable Metrics/ParameterLists
def
has_attachment?
attachment
.
present?
...
...
spec/factories/ci/test_case.rb
View file @
5b3dbbad
...
...
@@ -6,17 +6,18 @@ FactoryBot.define do
classname
{
"trace"
}
file
{
"spec/trace_spec.rb"
}
execution_time
{
1.23
}
status
{
"success"
}
status
{
Gitlab
::
Ci
::
Reports
::
TestCase
::
STATUS_SUCCESS
}
system_output
{
nil
}
attachment
{
nil
}
association
:job
,
factory: :ci_build
trait
:failed
do
status
{
"failed"
}
status
{
Gitlab
::
Ci
::
Reports
::
TestCase
::
STATUS_FAILED
}
system_output
{
"Failure/Error: is_expected.to eq(300) expected: 300 got: -100"
}
end
trait
:with_attachment
do
status
{
"failed"
}
status
{
Gitlab
::
Ci
::
Reports
::
TestCase
::
STATUS_FAILED
}
attachment
{
"some/path.png"
}
end
...
...
spec/lib/gitlab/ci/reports/test_case_spec.rb
View file @
5b3dbbad
...
...
@@ -4,21 +4,12 @@ require 'spec_helper'
describe
Gitlab
::
Ci
::
Reports
::
TestCase
do
describe
'#initialize'
do
let
(
:test_case
)
{
described_class
.
new
(
**
params
)}
let
(
:test_case
)
{
described_class
.
new
(
params
)}
context
'when both classname and name are given'
do
context
'when test case is passed'
do
let
(
:params
)
do
{
name:
'test-1'
,
classname:
'trace'
,
file:
'spec/trace_spec.rb'
,
execution_time:
1.23
,
status:
described_class
::
STATUS_SUCCESS
,
system_output:
nil
,
job:
build
(
:ci_build
)
}
end
let
(
:job
)
{
build
(
:ci_build
)
}
let
(
:params
)
{
attributes_for
(
:test_case
).
merge!
(
job:
job
)
}
it
'initializes an instance'
do
expect
{
test_case
}.
not_to
raise_error
...
...
@@ -34,16 +25,8 @@ describe Gitlab::Ci::Reports::TestCase do
end
context
'when test case is failed'
do
let
(
:params
)
do
{
name:
'test-1'
,
classname:
'trace'
,
file:
'spec/trace_spec.rb'
,
execution_time:
1.23
,
status:
described_class
::
STATUS_FAILED
,
system_output:
"Failure/Error: is_expected.to eq(300) expected: 300 got: -100"
}
end
let
(
:job
)
{
build
(
:ci_build
)
}
let
(
:params
)
{
attributes_for
(
:test_case
,
:failed
).
merge!
(
job:
job
)
}
it
'initializes an instance'
do
expect
{
test_case
}.
not_to
raise_error
...
...
@@ -59,36 +42,23 @@ describe Gitlab::Ci::Reports::TestCase do
end
end
context
'when classname is missing'
do
let
(
:params
)
do
{
name:
'test-1'
,
file:
'spec/trace_spec.rb'
,
execution_time:
1.23
,
status:
described_class
::
STATUS_SUCCESS
,
system_output:
nil
}
end
shared_examples
'param is missing'
do
|
param
|
let
(
:job
)
{
build
(
:ci_build
)
}
let
(
:params
)
{
attributes_for
(
:test_case
).
merge!
(
job:
job
)
}
it
'raises an error'
do
expect
{
test_case
}.
to
raise_error
(
ArgumentError
)
params
.
delete
(
param
)
expect
{
test_case
}.
to
raise_error
(
KeyError
)
end
end
context
'when name is missing'
do
let
(
:params
)
do
{
classname:
'trace'
,
file:
'spec/trace_spec.rb'
,
execution_time:
1.23
,
status:
described_class
::
STATUS_SUCCESS
,
system_output:
nil
}
end
context
'when classname is missing'
do
it_behaves_like
'param is missing'
,
:classname
end
it
'raises an error'
do
expect
{
test_case
}.
to
raise_error
(
ArgumentError
)
end
context
'when name is missing'
do
it_behaves_like
'param is missing'
,
:name
end
context
'when attachment is present'
do
...
...
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