Binary search through commits with Git bisect

Ever had a problem come up somewhere within a chain of commits, and you’re not sure which change caused the problem?  Up to now, we’ve usually addressed this by doing a binary search between the last commit and the latest commit we can find where the problem hasn’t yet been introduced.  I consider myself fairly experienced with Git, but I had no idea that it would do it for you!

The git bisect command is your friend in this case.  An excellent blog post explaining how to use it can be found here:

http://webchick.net/node/99

Mocking gesture recognisers with OCMock

Full credit for this tip goes to my colleague, Tom Kelly.  He doesn’t have a blog at this point, so I figured I’d blog the tip for him.

You can mock gesture recognisers like any other type of object.  Its not something I’d considered before, but this means that you can unit test gesture handling functionality on your classes by calling their gesture handling methods and passing your mock gesture recogniser.

Below is an example of a mock tap gesture recogniser:

id gestureMock = [OCMockObject partialMockForObject:[[UITapGestureRecognizer new] autorelease]];
[[[gestureMock stub] andReturnValue:OCMOCK_VALUE(CGPointZero)] locationInView:[OCMArg any]];

Then, in your unit test, you call the tap handler on your class under test:

-(void)testTapBehaviour
{
    // Set up control under test here...

    // Create the mock tap gesture handler
    id gestureMock = [OCMockObject partialMockForObject:[[UITapGestureRecognizer new] autorelease]];

    // Expect:
    [[[gestureMock stub] andReturnValue:OCMOCK_VALUE(CGPointZero)] locationInView:[OCMArg any]];
    // Set up any expected behaviours on your custom class here...

    // Call the tap handler method on your custom class here...
}