I would like to test method, that reads and writes value from NSUserDefaults
. Here is how read method looks like:
+ (NSDate *)initialImportDate
{
return [[NSUserDefaults standardUserDefaults] objectForKey:STBInitialImportDateKey];
}
I want to stub [NSUserDefaults standardUserDefaults]
and I was doing before and it worked perfectly. Assuming that we are stubbing class method, we have clear class stubs.
it(@"should load date from NSUserDefaults", ^{
NSDate *expectedDate = [NSDate date];
id mockNSDefaults = [NSUserDefaults nullMock];
[NSUserDefaults stub:@selector(standardUserDefaults) andReturn:mockNSDefaults];
[[mockNSDefaults should] receive:@selector(objectForKey:) andReturn:expectedDate withArguments:@"ImportDate"];
[[[Importer initialImportDate] should] equal:expectedDate];
[KWMock clearStubs];
});
When using Kiwi 2.2.4, I get error at the last line, that there is no class method, only instance one. As far I have no stub object, is it legal to got this way?
[[NSUserDefaults class] clearStubs];