objcio/issue-1-lighter-view-controllers

PhotosViewControllerTests failed

phamquy opened this issue · 2 comments

Just clone the source code, update submodule, and run the test
Note: the app is built and run normally

I've had the same issue. It errors out on the line:

UIView *view = photosViewController.view;

Giving the error:

test failure: -[PhotosViewControllerTests testNibLoading] failed: OCMockObject[UINavigationController]: expected method was not invoked: pushViewController:<OCMBlockConstraint: 0xf7521d0> animated:YES

However, the test will run and "pass" if you move these lines:

    // Trigger view did load:
    UIView *view = photosViewController.view;
    STAssertNotNil(view, @"");

to immediately after the initial creation of the PhotosViewController object. But, being new to objective C and OCMock, I'm not sure if that invalidates the test.

Just from the above, it seems at first blush like once the [[mockNavController expect] pushViewController] call is made, the testing framework expects the very next message to photosViewController to cause -pushViewController to be called, and then it errors out when the read of photosViewController.view fails to do that. But I'm still too new to this to feel sure that that's really what's going on. It seems like it would be an awkward limitation on a unit testing framework.

@phamquy @SpaceButler the issue is caused by -[UINavigationController _didGainChildScrollView] call, the mock object did not provide stub for that method. so the mock object just forward that call, the default implementation of forwarding just throw an exception.