Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Public iOS projects
Api
Commits
5e016016
Commit
5e016016
authored
Feb 07, 2017
by
Mauro E. Bender
Browse files
Close
#12
- Validate server responses
parent
1faa9293
Changes
2
Hide whitespace changes
Inline
Side-by-side
Api/Classes/Api.swift
View file @
5e016016
...
...
@@ -32,7 +32,7 @@ open class Api {
headers
:
[
String
:
String
]?
=
nil
,
completion
:
@escaping
(
DataResponse
<
Any
>
)
->
Void
)
{
Alamofire
.
request
(
urlForPath
(
path
)
.
absoluteString
,
method
:
method
,
parameters
:
parameters
,
encoding
:
encoding
,
headers
:
headers
)
.
responseJSON
(
completionHandler
:
completion
)
encoding
:
encoding
,
headers
:
headers
)
.
validate
(
)
.
responseJSON
(
completionHandler
:
completion
)
}
open
func
get
(
_
path
:
String
,
parameters
:
[
String
:
AnyObject
]?
=
nil
,
encoding
:
ParameterEncoding
=
URLEncoding
.
default
,
...
...
Example/Tests/ApiTests.swift
View file @
5e016016
...
...
@@ -18,6 +18,7 @@ class ApiTests: QuickSpec {
// Register stubs
stub
(
matchApiPath
(
"tests/get"
,
method
:
.
get
),
http
(
200
)
)
stub
(
matchApiPath
(
"tests/delete"
,
method
:
.
delete
),
http
(
200
)
)
stub
(
matchApiPath
(
"tests/unsuccess"
,
method
:
.
get
),
http
(
403
)
)
}
override
func
spec
()
{
...
...
@@ -37,6 +38,17 @@ class ApiTests: QuickSpec {
api
.
request
(
.
delete
,
path
:
"tests/delete"
)
{
result
in
done
()
}
}
}
context
(
"when the server responds with an unsuccessful status"
)
{
it
(
"should return an error"
)
{
waitUntil
{
done
in
api
.
request
(
.
get
,
path
:
"tests/unsuccess"
)
{
response
in
expect
(
response
.
result
.
isFailure
)
.
to
(
beTrue
())
done
()
}
}
}
}
}
describe
(
"get"
)
{
...
...
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