Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
A
Api
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
Public iOS projects
Api
Commits
5e016016
Commit
5e016016
authored
Feb 07, 2017
by
Mauro E. Bender
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Close #12 - Validate server responses
parent
1faa9293
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
1 deletion
+13
-1
Api/Classes/Api.swift
Api/Classes/Api.swift
+1
-1
Example/Tests/ApiTests.swift
Example/Tests/ApiTests.swift
+12
-0
No files found.
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