Ash Furrow:
Next, we create a mock connection, just like last time, except now we tell it to also expect a call to cancel
.
In addition to calling start
, we’re also going to manually invoke the NSURLConnectionDataDelegate
method connection:didReceiveResponse:
. This means we’ll need a response to pass in as the second parameter. That’s where the mockResponse
object comes in. We’ll create a mock NSHTTPURLResponse
that returns 404 when ask for its status code. This is how we will simulate the connection failure.
Objective-C OCMock Programming Testing
Mike Abdullah:
By declaring a @property as weak, it’s now impossible for it to be KVO-compliant. Weak properties are implemented simply by marking the underlying ivar as weak. If it gets cleared out to nil, that is handled directly by the runtime, without any sort of notification. Callers of the property will correctly start to receive nil, but none of your code know precisely it happened. Thus there’s no good way for a KVO notification to be posted at the time.
It seems like NSKeyValueObserving is due for a redesign.
Cocoa Key-Value Observing (KVO) Objective-C Programming