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];
});
});
});