Mocking NSManagedObject

Discussion of the OCMock framework. If you have patches we would prefer you to send them to the mailing list, but attaching them to a topic is possible, too.

Mocking NSManagedObject

Postby Eugene » 28 Aug 2015, 07:51

I try mocking Class successor from NSManagedObject (CoreData) using MagicalRecord
NSEntityDescription *pDesc = [NSEntityDescription entityForName:@"MyClacc"
inManagedObjectContext:[NSManagedObjectContext MR_defaultContext]];
MyClacc *modelForMocking = [[CKMyCard alloc] initWithEntity:pDesc
insertIntoManagedObjectContext:[NSManagedObjectContext MR_defaultContext]];
id myObjectMOCK = OCMPartialMock(modelForMocking);
OCMStub([myObjectMOCK valueForKey:@"property1"]).andReturn(@"test");
it works.
But I do not use in in the test code KVO and when I try to get the value through "." test fails :
"property1 unrecognized selector sent to instance ..."
what to do in this case, if you can not rewrite the code using KVO ?

Re: Mocking NSManagedObject

Postby erik » 06 Sep 2015, 15:13

So, you are implementing the pattern suggested in this article, right?

Purely from reading that article the following code should work:

Code: Select all
OCMStub([myObjectMOCK property1]).andReturn(@"test")

You seem to say that this is not the case. Can you confirm whether this works with the latest released version of OCMock, ie. OCMock 3.1.5?

And does the behaviour change on current master? I'm asking because I merged some code that allows stubbing of dynamic properties and as far as I can tell the managed objects are using dymanic properties.
Posts: 90
Joined: 10 Oct 2009, 15:22
Location: Hamburg, Germany

Return to OCMock