1

Intro

I'd like to test that the right frame is set on a views subview (which is injected as a mock).

However I can't seem to find a way to verify that the right CGRect is set

Current Attempt

-(void)testThatCorrectFrameIsSet {
  //Arrange
  MKTArgumentCaptor *argumentCaptor = [[MKTargumentCaptor alloc] init];
  self.sut.subView = mock([UIView class]);

  //Act
  [self.sut awakeFromNib];

  //Assert
  [[[MKTVerify(self.sut.subView) withMatcher:[argumentCaptor capture]] setFrame:CGSizeZero];

  expect([argumentCaptor.value CGRectValue].size.x).to.beCloseToWithin(42, 0.001);
}

What's going wrong

I get:

"NSInvalidArgumentException", "-[_NSInlineData CGRectValue]: unrecognized selector sent to instance 0x7af325c0"

Which makes me wonder how to correctly capture CGRect values

Side Note

I am aware of the fact that I could inject an actual UIView instead of a mocked one, however the actual code I'm testing prevents me from doing this for reasons that would make this question harder than needed.

Uri Agassi
  • 36,848
  • 14
  • 76
  • 93
Menno
  • 1,232
  • 12
  • 23

1 Answers1

1

I think you should use 'CGRectZero' instead of 'CGSizeZero', but this doesn't solve the Problem.

It looks like the captor value is not an NSValue.

//Arrange
MKTArgumentCaptor *argumentCaptor = [[MKTArgumentCaptor alloc] init];
UIView* subView = mock([UIView class]);

// Act
[subView setFrame:CGRectMake(1, 2, 3, 4)];

//Assert
[[MKTVerify(subView) withMatcher:[argumentCaptor capture]] setFrame:CGRectZero];

NSValue* capturedValue = [argumentCaptor value];
if (![capturedValue isKindOfClass:[NSValue class]])
{
    NSLog(@"Captured value is no NSValue!");
}

Hope this helps to track down the problem.

florieger
  • 1,310
  • 12
  • 22
  • Thanks, you were right on the CGRectZero part. However I know the captors value is not NSValue, how to get them is what i'm trying to find out :) – Menno Apr 20 '15 at 11:20
  • In this case an int is stored as a NSNumber, but I couldn't find anything about CGRect. http://stackoverflow.com/questions/20511562/ocmockito-capturing-primitive-types – florieger Apr 20 '15 at 11:30
  • Those should be stored in NSValue ;) – Menno Apr 20 '15 at 12:27