Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You have this line:</p> <pre><code>[locationManager setDelegate:delegateTarget]; </code></pre> <p>This means that when <code>locationManager:didFailWithError:</code> is called, the object that is passed for the <code>CLLocationManager</code> parameter will be your OCMock object named <code>locationManager</code> - AND NOT <code>trueLocationManager</code>. </p> <p>Your expectation:</p> <pre><code>[[delegateTarget expect] locationManager:trueLocationManager didFailWithError:[OCMArg any]]; </code></pre> <p>So, you are expecting a call that passes the <code>trueLocationManager</code>, but instead the partial mock is passed. Try expecting the partial mock to be passed.</p> <p>OCMock partial mocks, like <code>locationManager</code>, are just proxy wrappers over the real object, but their type is different (that's why you used <code>id</code> instead of real types). </p> <p>This magic works because of the way Objective-C handles calls through message passing. If you read a bit about the <a href="https://developer.apple.com/library/mac/documentation/cocoa/reference/foundation/classes/NSProxy_Class/Reference/Reference.html" rel="nofollow">NSProxy</a> and then you look at the <a href="https://github.com/erikdoe/ocmock" rel="nofollow">OCMock implementation</a> you will truly understand how some backstage stuff works.</p> <p>EDIT:</p> <p>Personally I don't know what do you really want to test. The Apple framework? None of the entities there are your classes/protocols. What are you testing?</p> <p>I guess you have a ViewController that implements the CLLocationManagerDelegate protocol. Mock that class. If your location manager is a property, stub it to return your fake location manager (so that internally the vc uses the fake). Or set the fake locationManager.delegate to be your ViewController. Start the fake location manager.</p> <p>Expect the ViewControllers delegate methods to be called. If your location manager is a singleton, then <a href="http://twobitlabs.com/2011/02/mocking-singletons-with-ocmock/" rel="nofollow">it's a bit tricky to replace it</a> with a fake/stub.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload