Slide 17
Slide 17 text
Swizzling in Swift
aerogear-ios-httpstub
corinnekrych.org
func testSucessfulPOST() {
// set up http stub
StubsManager.stubRequestsPassingTest({ (request: NSURLRequest!) -> Bool in
return true
}, withStubResponse: {(request: NSURLRequest!) -> StubResponse in
let data = NSJSONSerialization.dataWithJSONObject(["key":"value"], options: nil, error: nil)
return StubResponse(data: data!, statusCode: 200, headers: ["head1":"val1"])
})
var http = Http(baseURL: "http://whatever.com")
// async test expectation
let getExpectation = expectationWithDescription("POST http method test");
http.POST("/post", completionHandler: {(response, error) in
XCTAssertNil(error, "error should be nil")
XCTAssertTrue(response!["key"] as NSString == "value")
getExpectation.fulfill()
})
waitForExpectationsWithTimeout(10, handler: nil)
}