I'm trying to use OCMockito to stub an NSJSONSerialization
method. I thought I had a solution, but it turns out it causes this exception:
*** -[__NSArrayM objectAtIndex:]: index 2 beyond bounds [0 .. 1]
Here's what I was doing:
Class mockClass = MKTMockClass([NSJSONSerialization class]);
MKTOngoingStubbing *stubStepOne = MKTGiven([mockClass JSONObjectWithData:nil options:0 error:nil]);
id stubStepTwo = [stubStepOne withMatcher:anything() forArgument:1];
id stubStepThree = [stubStepTwo withMatcher:anything() forArgument:2];
[stubStepThree willReturn:mock([NSDictionary class])];
I'm guessing the problem is with the error argument, since that's meant to be passed by reference and I don't believe I've tried stubbing something like that before. Does anyone know a way to get this to work?
The goal here is to get the +[NSJSONSeralization JSONObjectWithData:option:error]
method to always return a mock NSDictionary when called from my test.