|
6 | 6 | // Copyright (c) 2014年 SwiftJSON. All rights reserved.
|
7 | 7 | //
|
8 | 8 |
|
9 |
| -import UIKit |
10 | 9 | import XCTest
|
11 | 10 | import Alamofire
|
12 | 11 | import SwiftyJSON
|
13 | 12 | import AlamofireSwiftyJSON
|
14 | 13 |
|
15 | 14 | class Alamofire_SwiftyJSONTests: XCTestCase {
|
16 | 15 |
|
17 |
| - func testJSONResponse() { |
| 16 | + func testGETRequestJSONResponse() { |
18 | 17 | let URL = "http://httpbin.org/get"
|
19 |
| - let expectation = expectationWithDescription("\(URL)") |
20 |
| - |
21 |
| - Alamofire.request(.GET, URL, parameters: ["foo": "bar"]).responseSwiftyJSON({(request, response, responseJSON, error) in |
22 |
| - expectation.fulfill() |
23 |
| - XCTAssertNotNil(request, "request should not be nil") |
24 |
| - XCTAssertNotNil(response, "response should not be nil") |
25 |
| - XCTAssertTrue(error == nil, "result error should be nil") |
26 |
| - XCTAssertEqual(responseJSON["args"], SwiftyJSON.JSON(["foo": "bar"] as NSDictionary), "args should be equal") |
27 |
| - }) |
28 |
| - waitForExpectationsWithTimeout(10) { (error) in |
29 |
| - XCTAssertNil(error, "\(error)") |
| 18 | + let parameters: Parameters = ["foo": "bar"] |
| 19 | + let expect = expectation(description: "responseSwiftyJSON method should work") |
| 20 | + Alamofire.request(URL, method: .get, parameters: parameters, encoding: URLEncoding.default) |
| 21 | + .validate() |
| 22 | + .responseSwiftyJSON { response in |
| 23 | + XCTAssertNotNil(response.request, "request should not be nil") |
| 24 | + XCTAssertNotNil(response.response, "response should not be nil") |
| 25 | + XCTAssertNil(response.error, "result error should be nil") |
| 26 | + XCTAssertEqual(response.value?["args"], SwiftyJSON.JSON(["foo": "bar"] as NSDictionary), "args should be equal") |
| 27 | + expect.fulfill() |
30 | 28 | }
|
| 29 | + waitForExpectations(timeout: 10.0, handler: nil) |
31 | 30 | }
|
32 |
| - |
33 | 31 | }
|
0 commit comments