次のような 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
spec を実行すると、このコード行で 1 つのエラーが発生します[[theValue(collection.objects.count) should] equal:theValue(1)];
context(@"then removing 1 object", ^{...})
ここに奇妙な部分があります -仕様からブロック全体を削除すると、前述のテストに合格します。
[collection removeObject:object]
これにより、失敗したテストの前に行が実行されていると私は信じています。ブロックが実行される順序を誤解している可能性があると感じています。
任意の提案をいただければ幸いです!