jangorman / hippolyte Goto Github PK
View Code? Open in Web Editor NEWHTTP Stubbing in Swift
License: MIT License
HTTP Stubbing in Swift
License: MIT License
Hi, concrats for your project!
Do you have a logotype? If you need one I can do it for free, I love to contribute to opensource projects, so if you want one just say it, Im here to help!
Greetings!
Nuno Jesus
Adding the @discardableResult on builder functions resolves compilation warnings when configuring the responsebuilder in several steps.
Ex: Result of call to 'stubResponse(withError:)' is unused
This is quick question not an issue.
DO you think this approach will wok to stub the Xcode UI Tests as well ?
@JanGorman Let me know what you think ?
Do you have any plans to bring 1.4.1 to cocoapods? This would be awesome
Hello. We are using version 1.2.3 of Hippolyte with Xcode 12.1, macOS Catalina 10.15.7. We are seeing that Hippolyte.shared.stop()
is not working the way we expect.
We have a test suite that includes tests where we do not want to mock HTTP transactions. Other tests in our test suite use Hippolyte where we do want mocking. Our tearDown()
function includes the call Hippolyte.shared.stop()
, but we are seeing tests where we do not want mocking fail with
Error Domain=Hippolyte.HTTPStubURLProtocol.NoMatchError Code=1 "(null)" UserInfo={_NSURLErrorRelatedURLSessionTaskErrorKey=(
"LocalDataTask <A5D03C08-843F-451B-9871-633EED5F4DC9>.<35>"
), _NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask <A5D03C08-843F-451B-9871-633EED5F4DC9>.<35>}
In the test suite, there are tests that use Hippolyte that execute before the failing test.
If we run the failing test by itself, it passes.
We expected Hippolyte.shared.stop()
to disable Hippolyte and allow unmocked HTTP transactions. Is that the correct expectation?
Hello, I'm getting 'Undefined symbols for architecture x86_64' after adding this framework. I've cleaned my derived data folder, made sure linker flags have '$(inherited) and made sure build archive arch was set to NO and I can't get this framework to build. Any ideas?
I was using Hippolyte to stub out my tests and found that the 304 response is not handled correctly.
https://github.com/JanGorman/Hippolyte/blob/master/Hippolyte/HTTPStubURLProtocol.swift#L46
// Original, incorrect:
if 300...399 ~= statusCode && (statusCode != 304 || statusCode != 305) {
// Fixed:
if 300...399 ~= statusCode && (statusCode != 304 && statusCode != 305) {
I'm not actually sure why 305 is handled at all, since I think that status code is not suggested, but 304 is a valid code.
Here is a test that can be added to the Hippolyte tests that demonstrates the failure:
func testItDoesNotStubsRedirectNoContent() {
let url = URL(string: "http://www.apple.com")!
var stub = StubRequest(method: .GET, url: url)
var response = StubResponse()
response = StubResponse(statusCode: 304)
stub.response = response
Hippolyte.shared.add(stubbedRequest: stub)
Hippolyte.shared.start()
let expectation = self.expectation(description: "Dies not stub network redirect call")
let delegate = BlockRedirectDelegate()
let session = URLSession(configuration: .default, delegate: delegate, delegateQueue: nil)
let task = session.dataTask(with: url) { data, _, _ in
expectation.fulfill()
}
task.resume()
wait(for: [expectation], timeout: 1)
XCTAssertEqual(delegate.redirectCallCount, 0)
}
Should I have forked and tried to submit a branch with the fix?
On our project that we use Hippolyte, using Hippolyte.shared.stop(), sometimes causes failing tests.
In order to make sure it doesn't break, I think, we need to check, if the state is isStarted, to unload hooks.
Hi,
I'm using the library to write test the stub the request response with some already saved responses in the tests code base. But, I would like to test for poor bandwidth and error connections, would that be possible with Hippolyte?
Hi,
I want to test the post Api call. But I am not getting how to send the parameters to request.
The sample code give is for .GET var stub = StubRequest(method: .GET, url: gitUrl)
Please help me out with .POST var stub = StubRequest(method: .POST, url: gitUrl)
I am keen to unit test, getting stub request not found while I have set it up rightly and passing a valid json data as a response.
pasting the error log, please guide me the correct way. Also I am making a request with POST method, but getting the request as GET in the error.
Printing description of error:
▿ Optional
▿ some : No matching stub found for https://testdemo/v0.4/login/
▿ request : https://testdemo/v0.4/login/
▿ url : Optional
▿ some : https://testdemo/v0.4/login/
- cachePolicy : 0
- timeoutInterval : 60.0
- mainDocumentURL : nil
- networkServiceType : __ObjC.NSURLRequest.NetworkServiceType
- allowsCellularAccess : true
▿ httpMethod : Optional
- some : "GET"
▿ allHTTPHeaderFields : Optional<Dictionary<String, String>>
- some : 0 elements
- httpBody : nil
- httpBodyStream : nil
- httpShouldHandleCookies : true
- httpShouldUsePipelining : false
(lldb)
Dependabot couldn't find a Gemfile for this project.
Dependabot requires a Gemfile to evaluate your project's current Ruby dependencies. It had expected to find one at the path: /Gemfile
.
If this isn't a Ruby project, or if it is a library, you may wish to disable updates for it from within Dependabot.
Just a question
Is it Carthage compatible?
If not, any plans for the compatibility in the nearest future?
Hello,
I am trying to test a POST request by sending CredentialParams struct containing the username & password.
As a response, I do expect valid access & refresh token, but when I try to run it up, it shows some weird error, which does not tell me a lot.
2022-07-01 13:29:41.737535+0300 Kollektiv Creators Staging[33888:4167655] Task .<1> finished with error [1] Error Domain=Hippolyte.HTTPStubURLProtocol.NoMatchError Code=1 "(null)" UserInfo={_NSURLErrorRelatedURLSessionTaskErrorKey=(
"LocalDataTask .<1>"
), _NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask .<1>}
My own code:
`let body = CredentialsParams(email: "[email protected]",
password: "nEjh35921")
let matcher = JSONMatcher(object: body)
let url = URL(string: "http://our-api-domain/api/v1/user/login")!
let response = StubResponse.Builder()
.stubResponse(withStatusCode: 204)
.build()
let request = StubRequest.Builder()
.stubRequest(withMethod: .POST, url: url)
.addMatcher(matcher)
.addResponse(response)
.build()
Hippolyte.shared.add(stubbedRequest: request)
Hippolyte.shared.start()
let expectation = self.expectation(description: "Stubs network call")
let task = URLSession.shared.dataTask(with: url) { data, _, _ in
print("Data \(data)") - Data is always nil
expectation.fulfill()
}
task.resume()
wait(for: [expectation], timeout: 1)`
Hi,
I'm trying to test a response using this http status code but it's not working. I don't know if it's possible to test that response withStatusCode
= 304
or there are any errors on my code.
Many thanks.
Hippolyte has worked great for testing a lot of different scenarios in our app, but there's one thing I haven't figured out how to test for, and that's behavior while a network request is in flight. For instance, I have a class that returns in flight tasks if the same file is requested again. Another class needs to handle cancellation while a request is in progress.
For other async operations that I've stubbed I'd do the following:
Hippolyte has a pause method, but from what I understand that just stops it from responding to requests temporarily.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.