context(@"stubbing methods on class mocks", ^{
let(classMockForSubjectClass, ^Class{
return [KWMock mockForClass:[ExampleClass class]];
});
describe(@"stubbing a class method with a block", ^{
it(@"should run the block when called", ^{
NSNumber * parameter = @8675309;
NSNumber * __block passedNumber = nil;
[classMockForSubjectClass stub:@selector(voidClassMethodWithParameter:) withBlock:^id(NSArray *params) {
passedNumber = params[0];
return nil;
}];
[classMockForSubjectClass voidClassMethodWithParameter:parameter];
[[passedNumber should] equal:parameter];
});
});
});
I would expect this to pass. Instead it fails with this error:
Assertions: 'stubbing methods on class mocks, stubbing a class method with a block, should run the
block when called' [FAILED], NSRangeException "*** -[__NSArrayM objectAtIndex:]: index 0 beyond
bounds for empty array" raised
Specifically, I would expect the params array to have one element, the passed NSNumber. Instead, it appears to be empty.
Please let me know if I am not setting up this test properly or if you cannot reproduce. If someone can confirm this is a Kiwi bug and not operator error, I will spend some time trying to fix it.
When using stub:withBlock: to stub a class method on a class mock, the block is called with an empty parameter array.
The following method is declared in ExampleClass:
Here is the spec:
I would expect this to pass. Instead it fails with this error:
Specifically, I would expect the params array to have one element, the passed NSNumber. Instead, it appears to be empty.
Here is a simple iOS project that demonstrates this error: https://github.com/jbelkins/KiwiBugExamples
Please let me know if I am not setting up this test properly or if you cannot reproduce. If someone can confirm this is a Kiwi bug and not operator error, I will spend some time trying to fix it.