Comments (5)
There is a test case that covers this scenario. Stubbing request are evaluated with LIFO order so it should work as expected. I would double check that the url that is executed matches the second stub.
from sbtuitesttunnel.
There is a test case that covers this scenario. Stubbing request are evaluated with LIFO order so it should work as expected. I would double check that the url that is executed matches the second stub.
I want the opposite to happen, I don't want the URLs to be considered the same, I'd like to treat myhost.com/v1/user/1234/contact
as a different URL than myhost.com/v1/user
since in the test runs they are called multiple times themselves, some type of exact match where it doesn't just match on the base url but the whole path
from sbtuitesttunnel.
I think we're stating the same: after setting
app.stubRequests(matching: SBTRequestMatch.init(url: "myhost.com/v1/user/1234/contact"),
response: SBTStubResponse(fileNamed: "user_contact.json"))
requests to myhost.com/v1/user/1234/contact
should return the "user_contact.json" stub and all other requests to myhost.com/v1/user
will return the "user.json" one.
Could you add a test case to cover specifically your case? Would be easier to debug if there's actually a problem.
from sbtuitesttunnel.
I think we're stating the same: after setting
app.stubRequests(matching: SBTRequestMatch.init(url: "myhost.com/v1/user/1234/contact"), response: SBTStubResponse(fileNamed: "user_contact.json"))
requests to
myhost.com/v1/user/1234/contact
should return the "user_contact.json" stub and all other requests tomyhost.com/v1/user
will return the "user.json" one.Could you add a test case to cover specifically your case? Would be easier to debug if there's actually a problem.
Yeah definitely, so if I write the tests like this with stubs in this order, both tests pass
func testURLPaths() {
app.stubRequests(matching: SBTRequestMatch(url: "httpbin.org/user"), response: SBTStubResponse(response: ["stubbed": 1]))
app.stubRequests(matching: SBTRequestMatch(url: "httpbin.org/user/100/contact"), response: SBTStubResponse(response: ["stubbed": 2]))
let result1 = request.dataTaskNetwork(urlString: "https://httpbin.org/user")
XCTAssertTrue(request.isStubbed(result1, expectedStubValue: 1))
let result2 = request.dataTaskNetwork(urlString: "httpbin.org/user/100/contact")
XCTAssertTrue(request.isStubbed(result2, expectedStubValue: 2))
XCTAssert(app.stubRequestsRemoveAll())
}
When you swap the stub order, the second test now fails because its returning 1 instead of the expected value 2
func testURLPaths() {
app.stubRequests(matching: SBTRequestMatch(url: "httpbin.org/user/100/contact"), response: SBTStubResponse(response: ["stubbed": 2]))
app.stubRequests(matching: SBTRequestMatch(url: "httpbin.org/user"), response: SBTStubResponse(response: ["stubbed": 1]))
let result1 = request.dataTaskNetwork(urlString: "https://httpbin.org/user")
XCTAssertTrue(request.isStubbed(result1, expectedStubValue: 1))
let result2 = request.dataTaskNetwork(urlString: "httpbin.org/user/100/contact")
XCTAssertTrue(request.isStubbed(result2, expectedStubValue: 2))
XCTAssert(app.stubRequestsRemoveAll())
}
In the above scenario is that what is expected? If so is there a way to get what I want to work?
from sbtuitesttunnel.
As mentioned stubRequests are evaluated in LIFO order so the above failure is the expected behaviour.
SBTRequestMatch accepts regular expressions so you might want to modify the second stub so that it doesn't match against /contact
.
app.stubRequests(matching: SBTRequestMatch(url: #"(?!.*\/contact)httpbin.org/user"#), response: SBTStubResponse(response: ["stubbed": 1]))
app.stubRequests(matching: SBTRequestMatch(url: "httpbin.org/user/100/contact"), response: SBTStubResponse(response: ["stubbed": 2]))
from sbtuitesttunnel.
Related Issues (20)
- Unclear how to use the library to monitor requests on multiple hosts HOT 1
- Can't install 9.0.0 HOT 5
- The GCDWebServer 4.0.0 release broke our builds HOT 5
- Update to GCDWebServer dependency causing conflict HOT 3
- Crash during app launch HOT 11
- Swift UI and Swift Concurrency Support HOT 9
- Rewrite Stubbed Responses HOT 2
- Xcode 15.0 support HOT 4
- Intermittent timeouts on iOS17/Xcode 15 HOT 2
- SBTUITestTunnel stops building HOT 3
- Cannot build the App HOT 2
- 'connection went invalid while waiting for a reply because a mach port died' error HOT 1
- How to use rewrite feature properly? HOT 2
- Can't submit to App Store Connect: Invalid font GCDWebUploader.bundle/fonts/glyphicons-halflings-regular.woff HOT 8
- The package product 'SBTUITestTunnelClient/SBTUITestTunnelServer' cannot be used as a dependency of this target because it uses unsafe build flags. HOT 2
- question about app.stubRequests HOT 1
- Monitored requests have no httpBody HOT 20
- SBTProxyURLProtocol calls completionHandler in the main thread HOT 4
- Crash when running UI tests in parallel
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sbtuitesttunnel.