Skip to content

Instantly share code, notes, and snippets.

@GE-N
Created August 16, 2015 09:51
Show Gist options
  • Save GE-N/508b17a3dfddac091153 to your computer and use it in GitHub Desktop.
Save GE-N/508b17a3dfddac091153 to your computer and use it in GitHub Desktop.
BDD#3 stub fail
context("Send SMS") {
// Specify API to Stub
let apiSendSMSStub = OHHTTPStubsTestBlock = { request -> Bool in
return request.URL!.path == "/api/sendsms"
}
it("should success") {
...
}
it("should failed") {
let failBlock: OHHTTPStubsResponseBlock = { request -> OHHTTPStubsResponse in
return OHHTTPStubsResponse(fileAtPath: OHPathForFile("sendsms-err400.json", self.dynamicType)!, statusCode: 400, headers: nil)
}
let failStub = OHHTTPStubs.stubRequestsPassingTest(apiSendSMSStub, withStubResponse: failBlock)
var sendResult: APIResult?
SMSAPI.sendSMS("08011122229991123", text: "Hello, fail world", callback : { result in
result = sendResult
}
expect(sendResult).toNotEventually(beNil())
expect(sendResult?.isSuccess()).toEventually(beFalse())
OHHTTPStubs.removeStub(failStub)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment