Skip to content

Instantly share code, notes, and snippets.

@leviwilson
Last active Aug 29, 2015
Embed
What would you like to do?
Kiwi Helper Class Question

Background

Warning: I do not know objective-c that well

I'm working in some specs. Sometimes I see an opportunity to use some test helpers to eliminate some duplication in my testing. I'd like to be able to create a helper class that is able to wrap some of these helper verification methods and re-use it to clean up some of my specs.

Problem

I don't have access to any of the should flavor of Kiwi verifications within my tester. I'm assuming because I'm not within the SPEC_BEGIN / SPEC_END (as those macros call other Kiwi methods).

The Question

What do I need to do in order to create a helper class to be able to utilize the should macros in Kiwi?

#import "Kiwi.h"
@interface SomeHelper : NSObject
-(void) shouldHave:(int)expectedCount OfSomethingOn:(SomeClass)someObject;
@end
SPEC_BEGIN(SomeClassSpec)
describe(@"SomeClass", ^{
__block SomeHelper* tester;
__block SomeClass* theClass;
beforeEach(^{
theClass
tester = [[SomeHelper alloc] init];
});
it(@"can utilize the helper", ^{
/** ... some setup ... **/
[tester shouldHave:7 OfSomethingOn:theClass];
});
});
SPEC_END
@implementation SomeHelper
-(void) shouldHave:(int)expectedCount OfSomethingOn:(SomeClass)someObject
{
/** ERROR: should is not avialable **/
[[theValue([someObject theCount]) should] equal:theValue(expectedCount)];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment