kylef / Mockingjay

An elegant library for stubbing HTTP requests with ease in Swift
BSD 3-Clause "New" or "Revised" License
1.49k stars 178 forks source link

Swift 3 + Alamofire 4 #65

Closed ssoper closed 7 years ago

ssoper commented 7 years ago

Tests were failing which was due to Alamofire’s SessionManager’s URLSessionConfiguration not having MockingjayProtocol in its list of URLProtocol classes. Turns out the swizzler was never being called. I fixed this in a fork.

Not sure if you had already planned on fixing this or had something else in mind to address it.

fuxx commented 7 years ago

We also would need a Swift 3 + Alamofire compliant version. Would be nice @kylef if you could merge @ssoper`s implementation or your own as Pod.

Keep up the work 👍 Thanks

deepumukundan commented 7 years ago

Method swizzling for UrlSessionConfiguration seems wonky in swift 3. This used to work in swift 2, but now in swift 3 if we use a custom urlsessionconfiguration (default, ephemeral or custom based on any of these), the intercepts are not working. A data task using URLSession.shared works, but not one using custom config (which is what the swizzle was solving for swift 2).

kylef commented 7 years ago

@ssoper Thanks for taking a look at this. I think the change you have made would still have some problems. If you was to create an Alamofire manager before you call stub, then it won't have the Mockingjay protocol enabled. People have come into this problem before when they use singletons or Managers created from the AppDelegate before the stub has been created during a test.

The change in d6ccdc65f99af40e845636212e2cad59019aafbe was designed to stub this early on to prevent this problem (raised in #50). I actually think https://github.com/kylef/Mockingjay/pull/66/files may have already fixed this in master. If you was using CocoaPods the Objective-C source handling the swizzling wasn't included and thus this didn't happen.

Is anything hitting this problem with the current master?

ssoper commented 7 years ago

Pointing to current master appears to fix my issues, thank you @kylef!