kiwi-bdd / Kiwi

Simple BDD for iOS
BSD 3-Clause "New" or "Revised" License
4.14k stars 512 forks source link

Stubbing a class method with a BOOL return value on a class mock results in error #606

Open jbelkins opened 9 years ago

jbelkins commented 9 years ago

When stubbing a class method that returns boolean on a class mock, an error occurs when trying to set the return value.

ExampleClass has a method with the following signature:

+ (BOOL)booleanClassMethod;

Here is the spec:

context(@"stubbing methods on class mocks", ^{

    let(classMockForSubjectClass, ^Class{
        return [KWMock mockForClass:[ExampleClass class]];
    });

    describe(@"stubbing a class method that returns boolean", ^{

        it(@"should return YES when stubbed", ^{
            [classMockForSubjectClass stub:@selector(booleanClassMethod) andReturn:theValue(YES)];
            BOOL result = [classMockForSubjectClass booleanClassMethod];
            [[theValue(result) should] beYes];
        });
    });
});

From the console:

Assertions:  'mocking a class method that returns boolean, should return YES when stubbed' [FAILED], 
KWStubException "wrapped stub value type (B) could not be converted to the target type (@)" raised

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.

silvaric commented 9 years ago

I have the same problem. How I can make it right? did you know?

AwayQu commented 7 years ago

It seems not support for scale value, i find the source is implements with method signature invoke, but not find the implement of match method signature return value with obj like this @(YES).

isimple4 commented 4 years ago

I changed theValue(YES) to theValue(1) in stub return, which works fine now in ver 3.0.