I have an error that seems to be related to OCMockObject PartialMock. When mocking an object and stubbing a method I get this unrecognized selector error which I'm pretty sure is an order or casting issue. Here's my test
STV_StreamServer *server = [NSEntityDescription insertNewObjectForEntityForName:@"STV_StreamServer"inManagedObjectContext:context];
id mockServer = [OCMockObject partialMockForObject:server];
[[[mockServer stub] andReturnValue:@YES] localURLPresent];
[[[mockServer stub] andReturnValue:@NO] remoteURLPresent];
id mockSUT = [OCMockObject partialMockForObject:sut];
[[[mockSUT stub] andReturnValue:@YES] canLiveStream:nil];
sut.streamServer = mockServer;
NSError *err = [mockSUT checkStreamingPlayabilityForUser:[self getUser:NO]];
XCTAssertNil(err, @"An error occured when basic user tried local playback");
sut is a STV_MediaServer. The error I get is [STV_MediaServer-0xb39aba0-407898154.181220 setStreamServer:]: unrecognized selector sent to instance 0xb39aba0
. So first off I see that the object type seems wrong since it now includes what looks like a memory location. This occurs when I mock my sut. I'm sure it's an order issue. Been googling for hours.
I have not reproduce your issue, but I think it is not possible to stub properties(the CoreData ones declared with @dynamic) in managed objects.
For this case you show, you can simply set the properties to the values you want - no need for stubs here.