Skip to content

Instantly share code, notes, and snippets.

@odrobnik
Last active August 29, 2015 14:17
Show Gist options
  • Save odrobnik/b2d80c4816d0de1cd207 to your computer and use it in GitHub Desktop.
Save odrobnik/b2d80c4816d0de1cd207 to your computer and use it in GitHub Desktop.
OCMock question
- (void)testLoginButtonTapped
{
// mock a Server
id serverMock = OCMClassMock([Server class]);
OCMStub([serverMock loginUserWithName:[OCMArg any] password:[OCMArg any]]).andReturn(YES);
_loginVC.serverToUse = serverMock;
// simulate input in name field
_loginVC.userTextField.text = @"foo";
[_loginVC.userTextField sendActionsForControlEvents:UIControlEventEditingChanged];
// simulate input in password field
_loginVC.passwordTextField.text = @"bar";
[_loginVC.passwordTextField sendActionsForControlEvents:UIControlEventEditingChanged];
// simulate login button press
[_loginVC.loginButton sendActionsForControlEvents:UIControlEventTouchUpInside];
// verify it has called the expected method
OCMVerify([serverMock loginUserWithName:[OCMArg any] password:[OCMArg any]]);
}
@wfrank2509
Copy link

The OCMVerifyAll(serverMock); does the check of the expected method call and parameters for you.

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