kiwi-bdd / Kiwi

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

SharedExample with multiple 'it' blocks #712

Closed iamprabal closed 6 years ago

iamprabal commented 6 years ago

Hi, Here's my code:

File 1 : SharedExample code

SHARED_EXAMPLES_BEGIN(GameGeneric) sharedExamplesFor(@"game", ^(NSDictionary data) { __block Game game;

beforeEach(^{
    game = [data objectForKey:@"gameObj"];
});

it(@"has 0 score", ^{
    [[theValue(game.gameScore.integerValue) should] beZero];
});

it(@"should conform GameUIActionListener", ^{
    [[game should] conformToProtocol:@protocol(GameUIActionListener)];
});

}); SHARED_EXAMPLES_END

File 2 : Spec code

SPEC_BEGIN(QuizGameSpec) describe(@"QuizGame", ^{ context(@"game init", ^{ __block Game* quizGame;

    beforeEach(^{
        quizGame = [[QuizGame alloc] init];
    });

    itBehavesLike(@"game", [NSDictionary dictionaryWithObjectsAndKeys:quizGame, @"gameObj", nil]);
});

}); SPEC_END

My observation: when I have only one 'it' block in the shared example above, it works fine. When I add 2 'it' blocks, the second one is marked failed without executing it (I put breakpoints to conclude this). I want to add a lot of 'it' blocks in my shared example that will validate that the game object (Quiz game or any other game) behaves like a game and then I shall validate the behaviour of specific game types in game-specific spec files. I searched as much as I could but didn't find any "SHARED EXAMPLE" code where there are multiple 'it' blocks inside the same SharedExample. Please forgive me if there is a really trivial and obvious mistake I'm making as I'm really just starting to use Kiwi (and loving it as well).