我正在尝试使用 OCMockito 来存根一个NSJSONSerialization
方法。我以为我有一个解决方案,但事实证明它会导致此异常:
*** -[__NSArrayM objectAtIndex:]:索引 2 超出范围 [0 .. 1]
这就是我正在做的事情:
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])];
我猜问题出在错误参数上,因为它是通过引用传递的,我不相信我以前尝试过存根类似的东西。有谁知道让这个工作的方法?
这里的目标是让该+[NSJSONSeralization JSONObjectWithData:option:error]
方法在从我的测试中调用时始终返回一个模拟 NSDictionary。