我有一个看起来像这样的 Kiwi 规范文件:
#import "Kiwi.h"
#import "MyCollection.h"
SPEC_BEGIN(CollectionSpec)
describe(@"Collection starting with no objects", ^{
MyCollection *collection = [MyCollection new];
context(@"then adding 1 object", ^{
MyObject *object = [MyObject new];
[collection addObject:object];
it(@"has 1 object", ^{
[collection shouldNotBeNil];
[collection.objects shouldNotBeNil];
[[theValue(collection.objects.count) should] equal:theValue(1)]; //failing test
});
context(@"then removing 1 object", ^{
[collection removeObject:object];
it(@"has 0 objects", ^{
[[theValue(collection.objects.count) should] equal:theValue(0)]; //passing test
});
});
});
});
SPEC_END
运行规范会导致这行代码出现一次失败[[theValue(collection.objects.count) should] equal:theValue(1)];
这是奇怪的部分 - 如果我从规范中删除整个context(@"then removing 1 object", ^{...})
块,则上述测试通过。
这让我相信这[collection removeObject:object]
条线在测试失败之前就被执行了。我有一种感觉,我可能误解了块的执行顺序。
任何建议,将不胜感激!