0

I have a macro for test purposes that creates a navigation controller, sets it as the root view controller of the main window and put the view controller being tested inside the navigation controller.

I also would like to for every invocation of pushViewController:animated: to change the animated parameter to NO.

How can I achieve that?

I tried using stub:withBlock: and then calling the pushViewController:animated: inside the block with the view controller being pushed (params[0]) and NO but this leads to an infinite loop.

There is also the stub:withArguments: but in that case I don't have the reference to the view controller being pushed since it's a macro used in several places.

The only way I could think about it is to use the stub:withBlock: and inside the block remove the stub and normally call pushViewController:params[0]:NO but I couldn't find a way to remove a stub.

Any help?

Raphael Oliveira
  • 7,751
  • 5
  • 47
  • 55

1 Answers1

0

Kiwi's stubbing functionality isn't really designed to do that.

There are two main things it's for:

  • Isolating the code under test from the rest of the system (by replacing a method implementation with a fake one)
  • Making assertions about the API contract between objects in the system

If you want to globally change the default behaviour of a method, I think what you're after is a more general-purpose method-swizzling solution. Kiwi's stubbing functionality may be implemented in part with swizzling, but it's a much more focused tool.

Adam Sharp
  • 3,618
  • 25
  • 29