ocmock icon indicating copy to clipboard operation
ocmock copied to clipboard

OCMock 3: Text field mocking fails in strange ways

Open patrickhartling opened this issue 10 years ago • 6 comments

I encountered an unexpected problem where simply creating a partial mock of an instance of UITextField contained within an other object results in this error if ‑resignFirstResponder is sent to the UITextField object:

-[OCMockTextFieldTest testCreateMock] failed: -[UITextInputTraits resignFirstResponder]: unrecognized selector sent to instance 0x102b05ba0

That was produced by running the test class I created to show the issue. I don't know the significance of this, but if the test method is written as follows, no error occurs:

- (void)testCreateMock
{
    UITextField *const textField = [UITextField new];
    id mockObject = OCMPartialMock(textField);
    [textField resignFirstResponder];
}

patrickhartling avatar Jul 29 '14 21:07 patrickhartling

With the recent changes made in response to some of the other issues reported this problem seems to have been fixed, too. Could you retry whether it works for you now?

erikdoe avatar Aug 20 '14 14:08 erikdoe

This issue still happens as of 8d323b34b173f1f02e5772c6f4f3b4d4c1466dfd.

patrickhartling avatar Aug 22 '14 21:08 patrickhartling

+1

rex-remind101 avatar Sep 03 '15 21:09 rex-remind101

+1

realf avatar Jan 19 '16 12:01 realf

+1

jakunico avatar Jan 19 '16 14:01 jakunico

It may be an issue with UITextField not being KVC-compliant. See http://stackoverflow.com/questions/6617472/why-does-valueforkey-on-a-uitextfield-throws-an-exception-for-uitextinputtraits for more details.

PatrickNLT avatar Feb 09 '16 18:02 PatrickNLT