Erik A. Hanson's Weblog

Expectacular

Posted: November 27th, 2010    Tags: My Software, Objective C, Unit Testing

I started working on a matcher library for Cocoa/Objective-C called Expectacular. My main goals were to have a syntax that I prefer over OCHamcrest‘s syntax, and to have something that XCode’s code sense feature will understand so it can autocomplete my code.

Here are some examples:

[Expect int:[myArray count] toEqual:4];

[Expect object:user.name toEqual:@"Fred"];

[Expect array:validTokens toContainObject:user.token];

[Expect block:^{
    [fluxCapacitor rethread];
} toThrowExceptionWithReason:@"Uncharged capacitors cannot be rethreaded."];

[Expect blockToNotThrowException:^{
    [fluxCapacitor charge];
    [fluxCapacitor rethread];
}];

and here are some screenshots of the code completion in action:

Check out the GitHub repo or the public Pivotal Tracker project.



Leave a Reply



(Comments are moderated to keep out spam. Please be patient.)