luisobo / Nocilla

Testing HTTP requests has never been easier. Nocilla: Stunning HTTP stubbing for iOS and Mac OS X.

Home Page:https://twitter.com/luisobo

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Nocilla never returns the stub

ivanruizscm opened this issue · comments

With this simply code i always get "dont work", any hints?
`

class API {
static let url = "http://www.google.com"

func test(callback:(String) -> Void) {
    request(.GET, API.url)
    .responseJSON { (response) in
        callback("dont work")
    }

}
}

class TestingTests: XCTestCase {

let api = API()
let nocilla = LSNocilla.sharedInstance()

override func setUp() {
    super.setUp()
    nocilla.start()
}

override func tearDown() {
    nocilla.clearStubs()
    nocilla.stop()
    super.tearDown()
}

func testSomething() {
    stubRequest("GET", API.url).andReturn(201).withBody("works")
    var testResult: String?
    api.test { (result) in
        testResult = result
    }
    expect(testResult).toEventually(equal("works"), timeout: 5)
}
}

`

here is a sample project testing with nsurlconnection and alamofire, www.ruiznadal.com/TestingWithNocilla.zip

You are always calling your callback with the string dont work With the current code, I don't see any other result you could get.

I haven't tested this yet but I think you want to call the callback with the response body?
callback(NSString(data: response.data!, encoding: NSUTF8StringEncoding))