Skip to content

Instantly share code, notes, and snippets.

@lukeredpath
Forked from anonymous/Expectations.mm
Last active December 10, 2015 16:09
Show Gist options
  • Save lukeredpath/4459505 to your computer and use it in GitHub Desktop.
Save lukeredpath/4459505 to your computer and use it in GitHub Desktop.
Quick preview of the new Mocky syntax. The previous syntax required passing an explicit builder object into the checking block. I tried to work around this with some macros to make it more readable but this seemed generally like a bad idea. The new version keeps macros to a minimum. I also felt the jMock syntax - verbatim - didn't feel quite rig…
- (void)testCanExpectSingleMethodCallAndPass
{
id<SomeProtocol> testObject = [context protocolMock:@protocol(SomeProtocol)];
[context check:^{
[[expectThat(testObject) receives] doSomething];
}];
[testObject doSomething];
assertContextSatisfied(context);
}
- (void)testCanExpectSingleMethodSpecificNumberOfTimes
{
id<SomeProtocol> testObject = [context protocolMock:@protocol(SomeProtocol)];
[context check:^{
[[expectThat(testObject) receivesExactly:3] doSomething];
}];
[testObject doSomething];
[testObject doSomething];
[testObject doSomething];
assertContextSatisfied(context);
}
- (void)testCanExpectSingleMethodMaximumNumberOfTimes
{
id<SomeProtocol> testObject = [context protocolMock:@protocol(SomeProtocol)];
[context check:^{
// the 'of' method is optional syntatic sugar
[[[expectThat(testObject) receivesAtMost:3] of] doSomething];
}];
[testObject doSomething];
[testObject doSomething];
[testObject doSomething];
[testObject doSomething];
assertContextSatisfied(context); // will fail!
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment