OCMock和返回基于相同模拟实例的不同值,意外返回值。

时间:2012-07-05 07:51:39

标签: ios ocmock

请参阅#if 0 ...#endif,如果启用则模拟按预期工作,调用方法preferencesGeneralUnits时返回1,如果禁用则模拟仍会返回前一个值0,尽管我们要求他返回1.

我的问题,是OCMock的错误吗?或者它是OCMock的预期用途?谢谢。

对于2.0.1和从最新源代码构建都不好。

任何想法或讨论都将受到赞赏,在此先感谢。

- (void) testFormattedDistanceValueWithMeters{
    id mockSettings = [OCMockObject mockForClass:[TnSettings class]];
    id mockClientModel = [TnClientModel createMockClientModel];
    [[[mockClientModel stub] andReturn:mockSettings] settings];

    [[[mockSettings stub] andReturn:[NSNumber numberWithInt:0]] preferencesGeneralUnits];

    NSNumber *meters = [NSNumber numberWithDouble:0.9];
    distance = [NSString formattedDistanceValueWithMeters:meters];
    STAssertEqualObjects(distance, @"0.9", @"testformattedEndTimeForTimeInSeconds failed");

    //--------------See here---------------------
    #if 0
    mockSettings = [OCMockObject mockForClass:[TnSettings class]];
    mockClientModel = [TnClientModel createMockClientModel];
    [[[mockClientModel stub] andReturn:mockSettings] settings];
    #endif
    [[[mockSettings stub] andReturn:[NSNumber numberWithInt:1]] preferencesGeneralUnits];

    meters = [NSNumber numberWithDouble:1];
    distance = [NSString formattedDistanceValueWithMeters:meters];
    STAssertEqualObjects(distance, @"3.3", @"testformattedEndTimeForTimeInSeconds failed");

    [TnClientModel releaseInstance];
    }

1 个答案:

答案 0 :(得分:1)

Erik Doernenburg的解释是合理的。