Skip to content

Instantly share code, notes, and snippets.

@interlock
Created April 19, 2012 23:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save interlock/2424790 to your computer and use it in GitHub Desktop.
Save interlock/2424790 to your computer and use it in GitHub Desktop.
Mock with Stub that returns CGPoint
it(@"touch event mock setup", ^{
UITouch *touchMock = [UITouch mock]; // this is important, it has the selector signature to cast the return type
CGPoint source = CGPointMake(5.0, 5.0);
[touchMock stub:@selector(locationInView:)andReturn:theValue(source)];
NSSet *set = [NSSet setWithObject:touchMock];
CGPoint pow = [touchMock locationInView:nil];
[[theValue(pow.x) should] equal:5.0 withDelta:0.1];
});
// vs
it(@"touch event mock fail with generic mock", ^{
id touchMock = [KWMock mock];
CGPoint source = CGPointMake(5.0, 5.0);
[touchMock stub:@selector(locationInView:)andReturn:theValue(source)];
NSSet *set = [NSSet setWithObject:touchMock];
CGPoint pow = [touchMock locationInView:nil];
[[theValue(pow.x) should] equal:5.0 withDelta:0.1];
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment