-
Notifications
You must be signed in to change notification settings - Fork 179
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
Nocilla support for NSURLSessionDataTask #50
Comments
+1 |
I'm having the same problem, but I think the problem is not with Nocilla. It seems like NSURLSession and NSURLProtocol doesn't play well together under a testing environment. In the example below the method + (BOOL)canInitWithRequest: is never called.
This was tested with XCode 5.0 (5A1412) and iOS 7 simulator. |
I believe the reason this is not working out of the box is because you have to register the LSHTTPStubURLProtocol via the NSUSerSessionConfiguration's protocolClasses array instead of using the registerClass method (see https://developer.apple.com/library/ios/documentation/Foundation/Reference/NSURLSessionConfiguration_class/Reference/Reference.html#//apple_ref/doc/uid/TP40013440-CH1-SW24). So something like this in your test setup
|
@gdunkle is correct that the This means getting this to work in testing is more difficult. You cannot modify the defaults in the way above because Unfortunately, if you are using Nocilla for automated UI testing, you'll need to figure out how you want to do that for only when running tests (I'm using a preprocessing statements, which I'm not happy with). |
Yeah it's non trivial but definitely doable (at least with AFNetworking). I have it working for my tests by first extending AFHTTPSessionManager
Then in my test I use a category to add a wrapper around the init method of HttpSessionManager and swizzle the initWithBaseURL and wrap_initWithBaseURL
Of course my example is using AFNetworking's extension of the NSUrlSession stuff but I imagine the same principals could be applied. This method has been working quite well for me. |
Helps allow users to work with `NSURLSession` instances, like luisobo#50.
My solution ended up being pretty simple. I already have a class which manages my Network.m
Then in my tests I just make sure to hijack it: MyAPIControllerTests.m
And then everything worked just fine. I had some trouble referencing |
@timshadel's fix worked for me! Would be awesome to get this included so we could use AFHTTPSessionManager out of the box! |
@timshadel looks like your fix was turned down in order to have issue #60 implemented. I can't seem to figure out how to get the solution in #60 to catch my
It lets the request go through just fine; no exception is raised. Do I need to register
Edit: stranger still, when Travis CI Pro checks out and builds my project, it raises the exception… but not on my local machine, not when running the exact same command that Travis runs (which is an |
I'm trying out Nocilla with AFNetworking 2.0 RC2 and it's not working. Am I missing something or does Nocilla not support NSURLSession and all the other new goodies in iOS7?
Here's an example, which does not work as I assumed it would
The text was updated successfully, but these errors were encountered: