You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I use several stubs, just implemented the third one and now running into problems:
extensionHTTPStubRequest{staticvarstubXY:HTTPStubRequest{HTTPStubRequest().match(urlRegex:"*/resources/user/*/info").stub(for:.get){ urlRequest, matchedStubRequest in
// getting here for the url https://example.com/resources/public/countries
...}}}
This should never be the case, right? I'm having another stub added before this that should handle this case.
The text was updated successfully, but these errors were encountered:
There was a logic error because match(urlRegex:) function and the init of HTTPStubRegExMatcher() should throw in case of the wrong regex pattern. It does not happen and it silently fails without adding the right matcher to the stub request object it creates.
The right regex could be (?s).*\/resources\/user\/(?s).*\/info.
An example with the fixes for throws in the commits above.
do{letstub=tryHTTPStubRequest().match(urlRegex:"(?s).*/resources/user/(?s).*/info").stub(for:.post){ urlRequest, matchedStubRequest in
// it captures the https://example.com/resources/user/searches/info
// but not https://example.com/resources/list/searches/info (for example)
HTTPStubResponse()}HTTPStubber.shared.add(stub: stub)letreq=HTTPRequest{
$0.url =URL(string:"https://example.com/resources/user/searches/info")
$0.method =.post
}letnewClient=HTTPClient(baseURL:nil)letresponse=tryawait req.fetch(newClient)}catch{
print("Failed to add stub due to an error: \(error))}
malcommac
changed the title
Stubs with regex not working properly?
match(urlRegex:) function and the init of HTTPStubRegExMatcher() does not throws in case of wrong regular expression pattern
Mar 23, 2022
I use several stubs, just implemented the third one and now running into problems:
This should never be the case, right? I'm having another stub added before this that should handle this case.
The text was updated successfully, but these errors were encountered: