Nocilla
Nocilla copied to clipboard
LSNocilla.sharedInstance().stop() Not working
I have a multiple test set, one of them uses nocilla so I execute LSNocilla.sharedInstance().start() when it begin and stop it at the end, but when the other test that needs actual internet runs I keep getting "NocillaUnexpectedRequest', reason: 'An unexpected HTTP request was fired.'"
I don't know what you mean by 'multiple test set'
Please provide sample code that reproduces the issue/more detail. I don't know how to look into it based on the info you have provided.
Just ran into and debugged this issue. The problem happens if you create a new URL session when Nocilla is running, then stop Nocilla and continue using the session.
Nocilla swizzles the URL protocols on the default configuration – it cleans them up from the default configuration, but when creating a new session they are likely transferred to the session object, so any session objects created continue intercepting requests.
https://github.com/luisobo/Nocilla/blob/master/Nocilla/Hooks/NSURLSession/LSNSURLSessionHook.m
Yep, just ran into this problem that @stepanhruda described.
- Test runs fine, expectation is fulfilled.
- In -tearDown, LSNocilla.sharedInstance().stop() is called.
- The request that is called as a result of the stubbed request gets intercepted after .calling .stop().
e.g. We stub /user/login to return 200 OK. Works fine, but sync data gets called as a result of successful login. We can stub that request too, but it makes no difference since it gets called after .stop(). In other words, at the moment when - (LSStubResponse *)responseForRequest:(id<LSHTTPRequest>)actualRequest {
is called, (lldb) po self.started
returns NO, and self.requests has 0 elements so it will always throw the exception.
I'm experiencing this too.
Right now i just fixed it by using an instance of the network client rather than the shared singleton.
But reproduction steps are the same.
I'm experiencing this too.
I "fixed" it with this workaround (calling the stop-function in the setUp()-functions code):
override func setUp() {
super.setUp()
if (LSNocilla.sharedInstance().isStarted) {
LSNocilla.sharedInstance().stop()
}
LSNocilla.sharedInstance().start()
...
}
override func tearDown() {
//LSNocilla.sharedInstance().stop() // causes "NocillaUnexpectedRequest', reason: 'An unexpected HTTP request was fired.'"
super.tearDown()
}