OCMock throwing NSInternalInconsistencyException when parameters are not the ones expected

StackOverflow https://stackoverflow.com/questions/5911760

  •  29-10-2019
  •  | 
  •  

Question

I'm setting up a mock object for a delegate object, to check that when the URL is nil, the delegate method is called with nil as parameters.

When the FileDownloadOperation behave as expected,the test pass, which is fine.

When the FileDownloadOperation doesn't call the delegate method, the test fails as expected.

But when the FileDownloadOperation calls the delegate method with something else than nil, instead of failing, the test crashes and no other tests are executed because OCMock throws :

'NSInternalInconsistencyException' reason: 'OCMockObject[FileDownloadOperationTest]: unexpected method invoked: data:<> forURL:nil

  -(void) testNilURL{
      // 1. Create an operation
      FileDownloadOperation * anOp = [[FileDownloadOperation alloc]init];
      // 2. set a nil URL
      anOp.URL = nil;
      // 3. set a mock delegate
      id mockDelegate = [OCMockObject mockForClass:[self class]];
      [[mockDelegate expect] data:[OCMArg isNil] forURL:[OCMArg isNil]];
      anOp.delegate = mockDelegate;
      // 4. launch operation
      [anOp main];
      // 5. ASSERT mock delegate is called with nil data
      STAssertNoThrow([mockDelegate verify], @"Delegate should be called with nil data and nil URL");
      [anOp release];
    }

Is it the expected behaviour ? or am I doing something wrong ? thanks !

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top