0

I am seeing an exception when mocking an object that is already under KVO observation. Here is a simplified example that shows the problem:

[sourceObject addObserver:destinationObject forKeyPath:@"stringProperty" options:NSKeyValueObservingOptionNew context:nil];
[OCMockObject partialMockForObject:sourceObject];
[sourceObject removeObserver:destinationObject forKeyPath:@"stringProperty"];

When calling "-removeObserver:forKeyPath:" I get an exception that I am not currently observing the object. If I call "-stopMocking" on the mock before calling "-removeObserver:forKeyPath:" everything works fine.

drewag
  • 93,393
  • 28
  • 139
  • 128

1 Answers1

0

Both OCMock and KVO dynamically subclass the object and they so they can't work properly together. The only real solution is to modify your tests in such a way to not have to mock the object under observation. Worst case you will have to create your own test subclass to be used while testing.

drewag
  • 93,393
  • 28
  • 139
  • 128