Mockingjay icon indicating copy to clipboard operation
Mockingjay copied to clipboard

Add stub after launch

Open shunmugarajrntbci opened this issue 7 years ago • 1 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

shunmugarajrntbci avatar Feb 22 '18 14:02 shunmugarajrntbci

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(...)

kylef avatar Feb 22 '18 14:02 kylef