0

I'm using Kiwi for tests and when I try to stub the class method [GAI sharedInstance], it doesn't work. Here is what I'm doing:

NSObject *gaiMock  = [KWMock nullMock];
[GAI stub:@selector(sharedInstance) andReturn:gaiMock];

When I break after these lines of code and compare them in the console, here is what I get:

(lldb) po [GAI sharedInstance]
<GAI: 0x10c42d940>

(lldb) po gaiMock
<KWMock: 0x112926600>

What am I doing wrong?

abc123
  • 8,043
  • 7
  • 49
  • 80

2 Answers2

0

Have you tried swizzling [GAI sharedInstance]? Swizzling is never an ideal solution, but perhaps it could help in this case. Create a category on GAI at the top of your Kiwi test file, and override the sharedInstance method.

Gabe
  • 727
  • 1
  • 6
  • 8
  • Good idea, I'll have to try that. But I still don't understand why what I'm doing is not working. Is it because I'm trying to stub a method of a static library? – abc123 Apr 23 '14 at 21:46
0

Try [GAI stub:@selector(sharedInstance)...], as stub methods will work on class objects just like they do on instances.

meisel
  • 2,151
  • 2
  • 21
  • 38