-
Notifications
You must be signed in to change notification settings - Fork 602
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
Never calling the stub #37
Comments
This is due to the way the new Please upgrade to at least |
Yeah sorry, I am currently using 3.0.0. Just updated the issue up there. Seems like the issue is with the singleton, is it required to call setEnable:ForSessionConfiguration: before creating the sharedInstance? |
According to what you have in the documentation:
The line in your test example: [OHHTTPStubs setEnabled:YES forSessionConfiguration:sessionConfig]; Shouldn't be there if its enabled by default. Is there something special with NSURLSessionConfiguration? |
No more that what I explained in the README. Yes there is something special with But you shouldn't need to call Note: Be sure anyway that you added the |
Yep, that's correct. I am getting this array for the protocol classes: (
OHHTTPStubsProtocol,
OHHTTPStubsProtocol
) But it is not doing the stub correctly, what should I print for you to know about the problem? Can we do hangout or something? |
One thing I didn't realize, you return a Anyway, can you put some breakpoints in both your |
Everything correct but this line is returning nil so the condition is return false [OHHTTPStubs.sharedInstance firstStubPassingTestForRequest:request] I think I found the issue, is in the singleton, when it adds the stub to the list it has this object as self <OHHTTPStubs: 0xa0df3f0> But when it is accesses sharedInstance in [OHHTTPStubs.sharedInstance firstStubPassingTestForRequest:request] Its object id is: <OHHTTPStubs: 0xa2bceb0> |
So that means that your code to Verify that |
Can you be more specific? I quite didn't understand your statement here ;) |
I don't know where you see this line in my test example?! I call this method nowhere in my Test Suites, indeed because it is not needed since I provided the swizzling to do it for you automagically. Are you sure you are using the right version of |
Yes, just removed that the +setEnable and still the same. So this is what I got from the debugging: +(id<OHHTTPStubsDescriptor>)stubRequestsPassingTest:(OHHTTPStubsTestBlock)testBlock
withStubResponse:(OHHTTPStubsResponseBlock)responseBlock
{
OHHTTPStubsDescriptor* stub = [OHHTTPStubsDescriptor stubDescriptorWithTestBlock:testBlock
responseBlock:responseBlock];
[OHHTTPStubs.sharedInstance addStub:stub];
NSLog(@"%@", OHHTTPStubs.sharedInstance) -> <OHHTTPStubs: 0xa0df3f0>
return stub;
}
+ (BOOL)canInitWithRequest:(NSURLRequest *)request
{
NSLog(@"%@", OHHTTPStubs.sharedInstance) -> <OHHTTPStubs: 0xa2bceb0>
return ([OHHTTPStubs.sharedInstance firstStubPassingTestForRequest:request] != nil);
}
So its adding the stub to object A, but it is looking for that stub in object B. |
Ok I understand your analyze but I don't get how come the Thx again for the investigation |
Ok, got it. The problem is on concurrency. It's actually getting a different Is there a different way to make it wait for the block calls? |
I can't understand why the problem can be on concurrency, whereas Can you post your complete code somewhere? I feel like only having pieces with your comments |
https://gist.github.com/alvarezloaiciga/6925055 I gave it a good range of timeout but it should not affect. |
Ok I'll test that. By the way, why did you use a global variables (which by definition is not thread-safe) for your onceToken and sharedInstance, instead of a static inside your |
Just to be able to reset the And thanks so much for your help! |
Which doesn't make any sense, as it won't get reinitialized even if you got another test case, as your onceToken would already have been used and there's no way to reset it, right? |
There is a way to reset it but I am not using it in this case. (I am actually reseting other singletons). You can move it to the method declaration to see if thats the issue. |
I ran you Unit Test (I guessed the superclass of your |
I even added a Still not understanding your issue. |
can we have a quick hangout? |
Not tonite, I'm quite doing too much things at once already this evening and late for everything ^^ But maybe if you still have the issue over the weekend. |
great, are you running the code in xcode 5? Cuz' you are using STAssert rather than XCT |
As said above, Xcode5 and SDK7 of course. (I couldn't even build AFNetworking 2.0 If I was not using Xcode5…) But I'm still using SenTestingKit as I haven't ported my tests to XCTest yet and my |
It is working know, but I needed to remove the pod file and just added the xcode project to the workspace. So it might be related to the pod? |
Could you try again your original method (the one that didn't work) with the latest version/commit/HEAD, to let me know if it completely fixes your original issue? Thx! |
Note: |
If for some reason you add the static OHHTTPStubs to both your project and your tests bundle, it will give you bad headaches because you'll end up with 2 bundles and 2 OHHTTPStubs singleton instances! This explains the different instances address despite the This happens if you mess with pods, adding and removing XCode targets, because pod-generated static libs may get stuck and not removed by I think it's better to add some documentation because it's a bad problem to trace down if you don't relize about multiple bundles. |
Hello again @danpizz We are struggling with a related issue in #47 and I finally understood all the implications that you explain when you were talking about having two bundles when running Unit Tests. I in fact did the following test, as you could see in #47:
So I have two questions that I hope you can help me with:
Thanks in advance for your feedback |
Hi, I tried to implement stubs on xcode 5 with afnetworking 2.0 and it is not working. My current version of OHHTTPStubs pod is 3.0.0
I am actually using an AFHTTPSessionManager singleton configured:
This is the method I am actually calling after the stub:
Is there something I am doing wrong?
The text was updated successfully, but these errors were encountered: