New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can't mock class method in Pod target #67
Comments
I'm not aware of any issues. Are you saying everything compiles cleanly, the test gets invoked, the calls above do not throw any exceptions and still the cacheFolder message doesn't get stubbed? That would be really odd. |
Ok, I've created example project to visualise this problem. Please clone this repo: https://github.com/badeleux/OCMockPodTest My output for test method:
This demo presents my problem. Stubbing mechanism works for ViewController which is in app target. Moreover stubbed method cacheFolder works in test file (OCMockPodTestTests.m:39 and 41) but no longer works in ViewController.m which is shown in line 40 |
I suspect you have include the AFNetworking classes twice in your binary. I think both your library includes libPods.a, meaning it will have a copy of all of those classes. Your test bundle also includes libPods.a, meaning it will have another copy of all those classes. In Xcode 5, it appears that in this situation (rather than duplicate symbol errors), that two versions of each Class get added to the ObjC runtime with the same name. NSClassFromString (which OCMock uses) will only find the first one, probably, and only mock that class. Hard class references in one or the other product will refer to the version of the Class linked with that product -- so your library version will point to the Class linked into your library, whilst your test class code will refer to the one compiled into the test bundle. OCMock will only modify one or the other. So... try removing libPods.a from the "link binary with libraries" build phase from either your library or the test bundle. They should either be provided bundled inside your library (in which case remove from the test case), or users should be expected to include them along with your library if they are using it, in which case remove libPods from your library target (and the test case, as a consumer of the library, would then need to include it). |
Right. Thanks! |
I am trying to mock static method in AFDownloadRequestOperation class (which is in Pods target)
In test file when I am trying to invoke this method, result is predictably correct, but when I am invoking this method in project target it turns out that method cacheFolder doesn't return @"/Volumes/test5M".
Is there any known issue that OCMock can't stub class methods in Pods target?
The text was updated successfully, but these errors were encountered: