kylef / Mockingjay

An elegant library for stubbing HTTP requests with ease in Swift

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add stub after launch

shunmugarajrntbci opened this issue · comments

Is it possible to add new stub after launch, after navigating few viewcontroller. I need to add new stub at 3rd screen replacing old stub

Yes, you can add stubs whenever you like. The one limitation is that you need to ensure that the NSURLSessionConfiguration includes MockingjayProtocol when the NSURLSession instance is created.

If you are using the default session and would like the configuration swizzled to contain mockingjay's session (default behaviour when you run Mockingjay in tests). Then you can call mockingjaySwizzleDefaultSessionConfiguration upfront (during app launch or such, providing it is before you create any NSURLSession that will performing the requests):

URLSessionConfiguration.mockingjaySwizzleDefaultSessionConfiguration()

Alternatively, when creating NSURLSession, you can add MockingjayProtocol to the list of protocol classes at the front:

let configuration = URLSessionConfiguration.defaultSessionConfiguration()
configuration.protocolClasses = [MockingjayProtocol.self] as [AnyClass] + configuration.protocolClasses!

let session = URLSession(configuration: configuration)

let task = session.dataWithRequest(...)