0
寻找对使用Kiwi只读属性没有多大帮助。 总之,我想测试_myReadOnlyDict是否被初始化。 问题是myReadOnlyDict
仍然是空的(没有内容),尽管在beforeEach
块它被嘲笑和增加一个值。如何使用Kiwi存储只读属性,Objective-C
// All these return 0
ad.myReadOnlyDict.count;
[[ad myReadOnlyDict] allKeys].count;
[ad myReadOnlyDict].count;
我在这里失踪了什么?
任何帮助表示赞赏!
请参阅下面的代码:
在AppDelegate.h我有一个porperty。
@property (nonatomic, readonly) NSDictionary * myReadOnlyDict;
在AppDelegate.m我有一个方法,这是从AppDelegate中的didFinishLaunchingWithOptions方法调用。
- (void)initConfig
{
_myReadOnlyDict = [NSJSONSerialization JSONObjectWithData:[self jsonData] options:nil error:nil];
}
我有一个猕猴桃试验建立
describe(@"App Delegate", ^{
__block AppDelegate *ad;
beforeEach(^{
ad = [[AppDelegate alloc] init];
NSMutableDictionary * mockedDict = [NSJSONSerialization nullMock];
mockedDict[@"my_data"] = @"my_value";
[ad stub:@selector(myReadOnlyDict) andReturn:mockedDict];
});
afterEach(^{
ad = nil;
});
context(@"when smth happens", ^{
it(@"should do smth else", ^{
[[ad should] receive:@selector(initConfig)];
// These three lines fail
[[theValue([ad myReadOnlyDict].count) shouldNot] equal:theValue(0)];
[[theValue(ad.myReadOnlyDict.count) shouldNot] equal:theValue(0)];
[[theValue([[ad myReadOnlyDict] allKeys].count) shouldNot] equal:theValue(0)];
[ad initConfig];
});
});
});