kiwi-bdd / Kiwi

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

Shared examples for specs. #681

Closed lolgear closed 8 years ago

lolgear commented 8 years ago

@sharplet Is there any capabilities to use sharedExamples like Rspec?

In Specta you could use:

SpecBegin(AlgorithmRS256)
describe(@"AlgorithmRS256", ^{
    NSString *algorithmBehaviour = @"AlgorithmRS256";
    NSString *algorithmKey = @"alg";

    sharedExamplesFor(algorithmBehaviour, ^(NSDictionary *data){
        __block id<JWTAlgorithm> algorithm;
        __block NSString *validTokenToDecode;
        __block NSString *invalidTokenToDecode;
        __block NSString *validPublicKeyCertificateString;
        __block NSString *invalidPublicKeyCertificateString;
        __block NSData *privateKeyCertificateData;
        __block NSString *algorithmName;
        __block NSDictionary *headerAndPayloadDictionary;

        __block void (^assertDecodedDictionary)(NSDictionary *);
        __block void (^assertToken)(NSString *);

        // context it
        // context it
        // context it 
        // many examples here
    )};
    context(@"Name", ^{
        itShouldBehaveLike(@"AlgorithmRS256", @{});
    });

    context(@"Clean", ^{
        itShouldBehaveLike(@"AlgorithmRS256", @{algorithmKey: [JWTAlgorithmRS256 new]});
    });
)};

SpecEnd
modocache commented 8 years ago

Thanks for the suggestion, @lolgear! Shared examples are an awesome idea! However, I'd recommend using Specta or Quick for that feature, since they already implement it. We probably don't have the resources to really explore this idea further in Kiwi, so I'm closing this for now.

ecaselles commented 8 years ago

@lolgear Yes, shared examples are available on Kiwi since v2.4 (see #600 on how to use them).