Question

I am working on kiwi framework for testing by following

myStack.m
- (id) init {
    if (self = [super init]) {
        _data = [[NSMutableArray alloc] initWithCapacity:4];
    }
    return self;
}
- (void) push:(int)numberToPush {
    [self.data addObject:numberToPush];
}
- (int)top {
    return [[self.data lastObject] integerValue];

}
-(int)numberOfItem {
    return [self.data count];
}

and testing is

SPEC_BEGIN(MyStack)

describe(@"The stack", ^{
    __block MyStack    *stack;
    context(@"when created", ^{
        beforeAll(^{
            stack = [[MyStack alloc] init];
        });
        it(@"is not nil.", ^{
            [stack shouldNotBeNil];
        });


        it(@"allows me to count the item of stack", ^{
            [stack push:5];
            [[stack should] haveCountOf:1];
        });
    });
});
SPEC_END

However, I am getting BAD_EXCESS with Expectations testing.I dont know why getting this error. All helps are welcomed here.

Was it helpful?

Solution

It looks like you are trying to add an int to your NSMutableArray. You can only add objects to an NSArray, not primitive types. Try boxing in an NSNumber in your implementation of push::

- (void) push:(int)numberToPush {
    [self.data addObject:@(numberToPush)];
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top