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
This test will fail. It seems I always need to specify everything after the host in the uri matcher. This is a bit inconvenient.
Because eg. I as mobile app developer don't want to care how the backend has structured the login endpoint in my tests or which endpoint version it is. I'm only interested in stubbing the login request.
thx. your suggested solution works, but not very intuitive on first sight. can you please elaborate more on the design decision of only matching full URIs instead of only partly matching?
I also noticed that it really needs to match the full URI including query parameters, which is very cumbersome in my case. The requests I want to simply mock have lots of query parameters.
My use case:
I want to write integration tests of my whole system. I want to test if our backend sends us a specific error code like 410 with some response body. So in those error case tests, I don't really care about any of those query parameters.
So my workaround is creating this new matcher to partly match the uri
let jsonString = """ ... """
let data = jsonString.data(using: .utf8)!
stub(partUri("/samples"), jsonData(data, status: 410))
I believe a mocking library should offer a built-in possibility to mock network requests in a very easy and very fast way. This includes only matching part of uri.
eg. instead of using the regex pattern "^\(pattern)$", simply use "\(pattern)" in URITemplate.swift. Maybe add some flags to turn it on/off.
Reacted by Rob Lester, Stuart Kent, Ichiro Hirata and Jerzy Świniarski
Activity
kylef commentedon Apr 20, 2018
That is intentional, it is designed to be the full URI of full path.
Try the following:
Buju77 commentedon Apr 23, 2018
thx. your suggested solution works, but not very intuitive on first sight. can you please elaborate more on the design decision of only matching full URIs instead of only partly matching?
Buju77 commentedon Apr 26, 2018
I also noticed that it really needs to match the full URI including query parameters, which is very cumbersome in my case. The requests I want to simply mock have lots of query parameters.
My use case:
I want to write integration tests of my whole system. I want to test if our backend sends us a specific error code like 410 with some response body. So in those error case tests, I don't really care about any of those query parameters.
So my workaround is creating this new matcher to partly match the uri
and then
I believe a mocking library should offer a built-in possibility to mock network requests in a very easy and very fast way. This includes only matching part of uri.
eg. instead of using the regex pattern
"^\(pattern)$", simply use"\(pattern)"in URITemplate.swift. Maybe add some flags to turn it on/off.