Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Class method stubbed with a block on class mock calls block with empty parameter array #607

Open
jbelkins opened this issue Apr 8, 2015 · 1 comment

Comments

@jbelkins
Copy link

jbelkins commented Apr 8, 2015

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:

+ (void)voidClassMethodWithParameter:(NSNumber *)number;

Here is the spec:

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.

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.

@ghost
Copy link

ghost commented Nov 24, 2015

I've just run into the same issue. Any solutions?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant