2

I am using UIAlertView+Blocks from https://github.com/ryanmaxwell/UIAlertView-Blocks, which adds a tapBlock property to UIAlertView, with OCMock.

   id mockView = [OCMockObject mockForClass:[UIAlertView class]];
   [[[mockView stub] andReturn:mockView] alloc];

   // this works
   [[mockView expect] setTapBlock:OCMOCK_ANY];

   // this doesn't, it doesn't know what tapBlock is
   [[mockResetPasswordView expect] tapBlock:OCMOCK_ANY];

The tapBlock is declared as @property (copy, nonatomic) UIAlertViewCompletionBlock tapBlock. I also would like to expect this to be called and delegate back to the original method.

dB.
  • 4,700
  • 2
  • 46
  • 51
  • 1
    You get that error because the method tapBlock: does not exist in any class. Would be good if you describe a little bit more what you want to test exactly. – e1985 Jan 20 '14 at 11:28
  • @e1985, it does exist, declared here: https://github.com/ryanmaxwell/UIAlertView-Blocks/blob/e362b5f9d65700033b84c01e7fd52128713474f4/UIAlertView%2BBlocks.h#L29 – dB. Jan 21 '14 at 14:29
  • 1
    Is your test importing that header file? Have you cast mockResetPasswordView to the appropriate type? Its also not clear what you mean by "works", does this compile without warnings? – ImHuntingWabbits Jan 21 '14 at 19:10
  • 1
    That property declaration is not creating a method named tapBlock:, but setTapBlock: and tapBlock, the setter and the getter, and it does so in UIAlertView. What do you want to do exactly? To stub the tapBlock getter in mockResetPasswordView, right? – e1985 Jan 21 '14 at 19:51
  • @e1985 Sorry, I wasn't clear. This tapBlock is a property to which we assign a function, then it's being called. I want to stub that call. – dB. Jan 21 '14 at 21:27

0 Answers0