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
ee49887f
Commit
ee49887f
authored
Jan 06, 2020
by
Vitali Tatarintev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor StackTracesController specs
* Rearrange tests * Remove duplication by extracting into before block
parent
2a485759
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
34 deletions
+20
-34
spec/controllers/projects/error_tracking/stack_traces_controller_spec.rb
...s/projects/error_tracking/stack_traces_controller_spec.rb
+20
-34
No files found.
spec/controllers/projects/error_tracking/stack_traces_controller_spec.rb
View file @
ee49887f
...
...
@@ -12,8 +12,7 @@ describe Projects::ErrorTracking::StackTracesController do
end
describe
'GET #index'
do
let_it_be
(
:issue_id
)
{
1234
}
let
(
:issue_id
)
{
1234
}
let
(
:issue_stack_trace_service
)
{
spy
(
:issue_stack_trace_service
)
}
subject
(
:get_stack_trace
)
do
...
...
@@ -24,33 +23,28 @@ describe Projects::ErrorTracking::StackTracesController do
expect
(
ErrorTracking
::
IssueLatestEventService
)
.
to
receive
(
:new
).
with
(
project
,
user
,
issue_id:
issue_id
.
to_s
)
.
and_return
(
issue_stack_trace_service
)
expect
(
issue_stack_trace_service
).
to
receive
(
:execute
).
and_return
(
service_response
)
get_stack_trace
end
context
'awaiting data'
do
before
do
expect
(
issue_stack_trace_service
).
to
receive
(
:execute
)
.
and_return
(
status: :error
,
http_status: :no_content
)
end
it
'returns no data'
do
get_stack_trace
let
(
:service_response
)
{
{
status: :error
,
http_status: :no_content
}}
it
'responds with no data'
do
expect
(
response
).
to
have_gitlab_http_status
(
:no_content
)
end
end
context
'service result is successful'
do
before
do
expect
(
issue_stack_trace_service
).
to
receive
(
:execute
)
.
and_return
(
status: :success
,
latest_event:
error_event
)
get_stack_trace
end
let
(
:service_response
)
{
{
status: :success
,
latest_event:
error_event
}
}
let
(
:error_event
)
{
build
(
:error_tracking_error_event
)
}
it
're
turns an error
'
do
it
're
sponds with success
'
do
expect
(
response
).
to
have_gitlab_http_status
(
:ok
)
end
it
'responds with error'
do
expect
(
response
).
to
match_response_schema
(
'error_tracking/issue_stack_trace'
)
end
...
...
@@ -65,34 +59,26 @@ describe Projects::ErrorTracking::StackTracesController do
let
(
:error_message
)
{
'error message'
}
context
'without http_status'
do
before
do
expect
(
issue_stack_trace_service
).
to
receive
(
:execute
)
.
and_return
(
status: :error
,
message:
error_message
)
end
it
'returns 400 with message'
do
get_stack_trace
let
(
:service_response
)
{
{
status: :error
,
message:
error_message
}
}
it
'responds with bad request'
do
expect
(
response
).
to
have_gitlab_http_status
(
:bad_request
)
end
it
'responds with error message'
do
expect
(
json_response
[
'message'
]).
to
eq
(
error_message
)
end
end
context
'with explicit http_status'
do
let
(
:http_status
)
{
:no_content
}
let
(
:service_response
)
{
{
status: :error
,
message:
error_message
,
http_status:
http_status
}
}
before
do
expect
(
issue_stack_trace_service
).
to
receive
(
:execute
).
and_return
(
status: :error
,
message:
error_message
,
http_status:
http_status
)
it
'responds with custom http status'
do
expect
(
response
).
to
have_gitlab_http_status
(
http_status
)
end
it
'returns http_status with message'
do
get_stack_trace
expect
(
response
).
to
have_gitlab_http_status
(
http_status
)
it
'responds with error message'
do
expect
(
json_response
[
'message'
]).
to
eq
(
error_message
)
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