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
8b79e803
Commit
8b79e803
authored
Dec 10, 2019
by
Vitali Tatarintev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Extract Sentry related shared examples
Extract Sentry related shared examples into a separate file
parent
2e46fff2
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
60 additions
and
114 deletions
+60
-114
spec/lib/sentry/client/projects_spec.rb
spec/lib/sentry/client/projects_spec.rb
+2
-57
spec/lib/sentry/client_spec.rb
spec/lib/sentry/client_spec.rb
+2
-57
spec/support/shared_examples/lib/sentry/client_shared_examples.rb
...port/shared_examples/lib/sentry/client_shared_examples.rb
+56
-0
No files found.
spec/lib/sentry/client/projects_spec.rb
View file @
8b79e803
...
...
@@ -12,15 +12,6 @@ describe Sentry::Client::Projects do
)
end
# Requires sentry_api_request and subject to be defined
shared_examples
'calls sentry api'
do
it
'calls sentry api'
do
subject
expect
(
sentry_api_request
).
to
have_been_requested
end
end
shared_examples
'has correct return type'
do
|
klass
|
it
"returns objects of type
#{
klass
}
"
do
expect
(
subject
).
to
all
(
be_a
(
klass
)
)
...
...
@@ -31,52 +22,6 @@ describe Sentry::Client::Projects do
it
{
expect
(
subject
.
length
).
to
eq
(
length
)
}
end
# Requires sentry_api_url and subject to be defined
shared_examples
'no redirects'
do
let
(
:redirect_to
)
{
'https://redirected.example.com'
}
let
(
:other_url
)
{
'https://other.example.org'
}
let!
(
:redirected_req_stub
)
{
stub_sentry_request
(
other_url
)
}
let!
(
:redirect_req_stub
)
do
stub_sentry_request
(
sentry_api_url
,
status:
302
,
headers:
{
location:
redirect_to
}
)
end
it
'does not follow redirects'
do
expect
{
subject
}.
to
raise_exception
(
Sentry
::
Client
::
Error
,
'Sentry response status code: 302'
)
expect
(
redirect_req_stub
).
to
have_been_requested
expect
(
redirected_req_stub
).
not_to
have_been_requested
end
end
shared_examples
'maps exceptions'
do
exceptions
=
{
Gitlab
::
HTTP
::
Error
=>
'Error when connecting to Sentry'
,
Net
::
OpenTimeout
=>
'Connection to Sentry timed out'
,
SocketError
=>
'Received SocketError when trying to connect to Sentry'
,
OpenSSL
::
SSL
::
SSLError
=>
'Sentry returned invalid SSL data'
,
Errno
::
ECONNREFUSED
=>
'Connection refused'
,
StandardError
=>
'Sentry request failed due to StandardError'
}
exceptions
.
each
do
|
exception
,
message
|
context
"
#{
exception
}
"
do
before
do
stub_request
(
:get
,
sentry_request_url
).
to_raise
(
exception
)
end
it
do
expect
{
subject
}
.
to
raise_exception
(
Sentry
::
Client
::
Error
,
message
)
end
end
end
end
describe
'#list_projects'
do
let
(
:sentry_list_projects_url
)
{
'https://sentrytest.gitlab.com/api/0/projects/'
}
let
(
:sentry_api_response
)
{
projects_sample_response
}
...
...
@@ -141,7 +86,7 @@ describe Sentry::Client::Projects do
context
'redirects'
do
let
(
:sentry_api_url
)
{
sentry_list_projects_url
}
it_behaves_like
'no redirects'
it_behaves_like
'no
Sentry
redirects'
end
# Sentry API returns 404 if there are extra slashes in the URL!
...
...
@@ -166,7 +111,7 @@ describe Sentry::Client::Projects do
context
'when exception is raised'
do
let
(
:sentry_request_url
)
{
sentry_list_projects_url
}
it_behaves_like
'maps exceptions'
it_behaves_like
'maps
Sentry
exceptions'
end
end
...
...
spec/lib/sentry/client_spec.rb
View file @
8b79e803
...
...
@@ -20,28 +20,6 @@ describe Sentry::Client do
subject
(
:client
)
{
described_class
.
new
(
sentry_url
,
token
)
}
# Requires sentry_api_url and subject to be defined
shared_examples
'no redirects'
do
let
(
:redirect_to
)
{
'https://redirected.example.com'
}
let
(
:other_url
)
{
'https://other.example.org'
}
let!
(
:redirected_req_stub
)
{
stub_sentry_request
(
other_url
)
}
let!
(
:redirect_req_stub
)
do
stub_sentry_request
(
sentry_api_url
,
status:
302
,
headers:
{
location:
redirect_to
}
)
end
it
'does not follow redirects'
do
expect
{
subject
}.
to
raise_exception
(
Sentry
::
Client
::
Error
,
'Sentry response status code: 302'
)
expect
(
redirect_req_stub
).
to
have_been_requested
expect
(
redirected_req_stub
).
not_to
have_been_requested
end
end
shared_examples
'issues has correct return type'
do
|
klass
|
it
"returns objects of type
#{
klass
}
"
do
expect
(
subject
[
:issues
]).
to
all
(
be_a
(
klass
)
)
...
...
@@ -52,39 +30,6 @@ describe Sentry::Client do
it
{
expect
(
subject
[
:issues
].
length
).
to
eq
(
length
)
}
end
# Requires sentry_api_request and subject to be defined
shared_examples
'calls sentry api'
do
it
'calls sentry api'
do
subject
expect
(
sentry_api_request
).
to
have_been_requested
end
end
shared_examples
'maps exceptions'
do
exceptions
=
{
Gitlab
::
HTTP
::
Error
=>
'Error when connecting to Sentry'
,
Net
::
OpenTimeout
=>
'Connection to Sentry timed out'
,
SocketError
=>
'Received SocketError when trying to connect to Sentry'
,
OpenSSL
::
SSL
::
SSLError
=>
'Sentry returned invalid SSL data'
,
Errno
::
ECONNREFUSED
=>
'Connection refused'
,
StandardError
=>
'Sentry request failed due to StandardError'
}
exceptions
.
each
do
|
exception
,
message
|
context
"
#{
exception
}
"
do
before
do
stub_request
(
:get
,
sentry_request_url
).
to_raise
(
exception
)
end
it
do
expect
{
subject
}
.
to
raise_exception
(
Sentry
::
Client
::
Error
,
message
)
end
end
end
end
describe
'#list_issues'
do
let
(
:issue_status
)
{
'unresolved'
}
let
(
:limit
)
{
20
}
...
...
@@ -158,7 +103,7 @@ describe Sentry::Client do
context
'redirects'
do
let
(
:sentry_api_url
)
{
sentry_url
+
'/issues/?limit=20&query=is:unresolved'
}
it_behaves_like
'no redirects'
it_behaves_like
'no
Sentry
redirects'
end
# Sentry API returns 404 if there are extra slashes in the URL!
...
...
@@ -249,7 +194,7 @@ describe Sentry::Client do
end
end
it_behaves_like
'maps exceptions'
it_behaves_like
'maps
Sentry
exceptions'
context
'when search term is present'
do
let
(
:search_term
)
{
'NoMethodError'
}
...
...
spec/support/shared_examples/lib/sentry/client_shared_examples.rb
0 → 100644
View file @
8b79e803
# frozen_string_literal: true
# Requires sentry_api_request and subject to be defined
RSpec
.
shared_examples
'calls sentry api'
do
it
'calls sentry api'
do
subject
expect
(
sentry_api_request
).
to
have_been_requested
end
end
# Requires sentry_api_url and subject to be defined
RSpec
.
shared_examples
'no Sentry redirects'
do
let
(
:redirect_to
)
{
'https://redirected.example.com'
}
let
(
:other_url
)
{
'https://other.example.org'
}
let!
(
:redirected_req_stub
)
{
stub_sentry_request
(
other_url
)
}
let!
(
:redirect_req_stub
)
do
stub_sentry_request
(
sentry_api_url
,
status:
302
,
headers:
{
location:
redirect_to
}
)
end
it
'does not follow redirects'
do
expect
{
subject
}.
to
raise_exception
(
Sentry
::
Client
::
Error
,
'Sentry response status code: 302'
)
expect
(
redirect_req_stub
).
to
have_been_requested
expect
(
redirected_req_stub
).
not_to
have_been_requested
end
end
RSpec
.
shared_examples
'maps Sentry exceptions'
do
exceptions
=
{
Gitlab
::
HTTP
::
Error
=>
'Error when connecting to Sentry'
,
Net
::
OpenTimeout
=>
'Connection to Sentry timed out'
,
SocketError
=>
'Received SocketError when trying to connect to Sentry'
,
OpenSSL
::
SSL
::
SSLError
=>
'Sentry returned invalid SSL data'
,
Errno
::
ECONNREFUSED
=>
'Connection refused'
,
StandardError
=>
'Sentry request failed due to StandardError'
}
exceptions
.
each
do
|
exception
,
message
|
context
"
#{
exception
}
"
do
before
do
stub_request
(
:get
,
sentry_request_url
).
to_raise
(
exception
)
end
it
do
expect
{
subject
}
.
to
raise_exception
(
Sentry
::
Client
::
Error
,
message
)
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