Skip to content

Instantly share code, notes, and snippets.

@lukeredpath
Created July 22, 2010 11:38
Show Gist options
  • Select an option

  • Save lukeredpath/485866 to your computer and use it in GitHub Desktop.

Select an option

Save lukeredpath/485866 to your computer and use it in GitHub Desktop.
# potential syntatic sugar using a macro, which depends on yielding a specifically named builder param:
#define expect(arg) [builder expect:arg]
[context checking:^(LRExpectationBuilder *builder){
[expect(object) doSomething];
}];
@implementation MockeryTests
- (void)setUp;
{
testCase = [MockTestCase new];
context = [LRMockery mockeryForTestCase:testCase];
}
- (void)testCanExpectSingleMethodCallAndPass;
{
SimpleObject *testObject = [context mock:[SimpleObject class]];
[context checking:^(LRExpectationBuilder *will){
[[will expect:testObject] doSomething];
}];
[testObject doSomething];
[context assertSatisfied];
STAssertTrue([testCase numberOfFailures] == 0, @"expected zero failures, got %d.", [testCase numberOfFailures]);
}
- (void)testCanExpectSingleMethodCallAndFail;
{
SimpleObject *testObject = [context mock:[SimpleObject class]];
[context checking:^(LRExpectationBuilder *will){
[[will expect:testObject] doSomething];
}];
[context assertSatisfied];
STAssertTrue([testCase numberOfFailures] == 1, @"expected 1 failure, got %d.", [testCase numberOfFailures]);
}
@end
@lukeredpath
Copy link
Copy Markdown
Author

The first passing functional tests for my Objective C jMock clone. Why another Obj-C mock library. Well, there's only one I know of (OCMock) and I sorry, I don't think its great. Why port jMock instead of a Ruby library like Mocha? As much as I like Mocha, I don't think its message-chaining syntax would work well with Obj-C (too many square brackets) so I've taken the jMock approach, which I think is elegant.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment