{"id":19267300,"url":"https://github.com/jangorman/hippolyte","last_synced_at":"2025-04-10T04:58:34.243Z","repository":{"id":40596912,"uuid":"102874660","full_name":"JanGorman/Hippolyte","owner":"JanGorman","description":"HTTP Stubbing in Swift","archived":false,"fork":false,"pushed_at":"2024-07-11T14:07:06.000Z","size":152,"stargazers_count":111,"open_issues_count":2,"forks_count":17,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-04-03T00:09:30.829Z","etag":null,"topics":["carthage","cocoapods","http-stub","ios","macos","mock","mocking","spm","stub","stubbing","swift","swift-5","swift-package-manager","swift5","test","testing","xctest"],"latest_commit_sha":null,"homepage":null,"language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/JanGorman.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-09-08T15:13:59.000Z","updated_at":"2025-03-27T14:00:19.000Z","dependencies_parsed_at":"2024-11-09T20:11:32.025Z","dependency_job_id":"29e7d14a-68d0-4ae7-93c3-5066978a9435","html_url":"https://github.com/JanGorman/Hippolyte","commit_stats":{"total_commits":117,"total_committers":21,"mean_commits":5.571428571428571,"dds":"0.49572649572649574","last_synced_commit":"5b393c644c84877f36e461ae6d8209d35161e098"},"previous_names":[],"tags_count":22,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JanGorman%2FHippolyte","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JanGorman%2FHippolyte/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JanGorman%2FHippolyte/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JanGorman%2FHippolyte/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/JanGorman","download_url":"https://codeload.github.com/JanGorman/Hippolyte/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248161265,"owners_count":21057554,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["carthage","cocoapods","http-stub","ios","macos","mock","mocking","spm","stub","stubbing","swift","swift-5","swift-package-manager","swift5","test","testing","xctest"],"created_at":"2024-11-09T20:11:27.829Z","updated_at":"2025-04-10T04:58:34.220Z","avatar_url":"https://github.com/JanGorman.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Hippolyte\n\n![Run tests](https://github.com/JanGorman/Hippolyte/workflows/CI/badge.svg)\n[![codecov](https://codecov.io/gh/JanGorman/Hippolyte/branch/master/graph/badge.svg)](https://codecov.io/gh/JanGorman/Hippolyte)\n[![Version](https://img.shields.io/cocoapods/v/Hippolyte.svg?style=flat)](http://cocoapods.org/pods/Hippolyte)\n[![License](https://img.shields.io/cocoapods/l/Hippolyte.svg?style=flat)](http://cocoapods.org/pods/Hippolyte)\n[![Platform](https://img.shields.io/cocoapods/p/Hippolyte.svg?style=flat)](http://cocoapods.org/pods/Hippolyte)\n\nAn HTTP stubbing library written in Swift.\n\n## Requirements\n\n- Swift 5\n- iOS 12+\n- macOS 10.13+\n\n## Install\n\n### Cocoapods\n\nHippolyte is available on [Cocoapods](http://cocoapods.org). Add it to your `Podfile`'s test target:\n\n```ruby\npod 'Hippolyte'\n```\n\n### Carthage\n\nHippolyte is also available on [Carthage](https://github.com/Carthage/Carthage). Make the following entry in your Cartfile:\n\n```ruby\ngithub \"JanGorman/Hippolyte\"\n```\n\nThen run `carthage update`.\n\nAdd the Hippolyte.framework to the `Link Binary with Libraries`.\n\nYou'll need to go through some additional steps.\nPlease see [here](https://github.com/Carthage/Carthage#quick-start).\n\n## Usage\n\nTo stub a request, first you need to create a `StubRequest` and `StubResponse`. You then register this stub with `Hippolyte` and tell it to intercept network requests by calling the `start()` method.\n\nThere are convenient Builder classes for both requests and responses:\n\n```swift\nfunc testStub() {\n  // The stub response\n  let response = StubResponse.Builder()\n    .stubResponse(withStatusCode: 204)\n    .addHeader(withKey: \"X-Foo\", value: \"Bar\")\n    .build()\n  // The request that will match this URL and return the stub response\n  let request = StubRequest.Builder()\n    .stubRequest(withMethod: .GET, url: URL(string: \"http://www.apple.com\")!)\n    .addResponse(response)\n    .build()\n  // Register the request\n  Hippolyte.shared.add(stubbedRequest: request)\n  // And start intercepting requests by calling start\n  Hippolyte.shared.start()\n  …\n}\n```\n\nAlternatively you can also construct them directly:\n\n```swift\nfunc testStub() {\n  let url = URL(string: \"http://www.apple.com\")!\n  var stub = StubRequest(method: .GET, url: url)\n  var response = StubResponse()\n  let body = \"Hippolyte\".data(using: .utf8)!\n  response.body = body\n  stub.response = response\n  Hippolyte.shared.add(stubbedRequest: stub)\n  Hippolyte.shared.start()\n\n  let expectation = self.expectation(description: \"Stubs network call\")\n  let task = URLSession.shared.dataTask(with: url) { data, _, _ in\n    XCTAssertEqual(data, body)\n    expectation.fulfill()\n  }\n  task.resume()\n\n  wait(for: [expectation], timeout: 1)\n}\n```\n\nIt's also possible to configure a `StubRequest` to use a regular expression matcher to intercept URLs. The following example also shows a `StubResponse` that returns a certain status code:\n\n```swift\nfunc testStub() throws {\n  let regex = try NSRegularExpression(pattern: \"http://www.google.com/+\", options: [])\n  var stub = StubRequest(method: .GET, urlMatcher: RegexMatcher(regex: regex))\n  stub.response = StubResponse(statusCode: 404)\n  Hippolyte.shared.add(stubbedRequest: stub)\n  Hippolyte.shared.start()\n\n  myFictionalDataSource.get(URL(string: \"http://www.google.com/foo.html\")!) {\n    …\n  }\n}\n```\n\nTo match a POST request on the body that's sent, `Hippolyte` uses a `Matcher`. There is a ready made `DataMatcher` and `JSONMatcher` class available to use. Say you're POSTing a JSON to your server, you could make your stub match a particular value like this:\n\n```swift\nstruct MyPostBody: Codable, Hashable {\n  let id: Int\n  let name: String\n}\n\nfunc testStub() throws {\n  // The POST body that you want to match\n  let body = MyPostbody(id: 100, name: \"Tim\")\n  let matcher = JSONMatcher\u003cMyPostBody\u003e(object: body)\n  // Construct your stub response\n  let response = StubResponse.Builder()\n    .stubResponse(withStatusCode: 204)\n    .build()\n  // The request that will match the URL and the body JSON\n  let request = StubRequest.Builder()\n    .stubRequest(withMethod: .POST, url: URL(string: \"http://www.apple.com\")!)\n    .addMatcher(matcher)\n    .addResponse(response)\n    .build()\n}\n```\n\n### Delegate\n\nYou can add an optional `ResponseDelegate` into the mix to be notified when a response is mocked by Hippolyte. It has only one method `onResponse`.\n\n### Teardown\n\nRemember to tear down stubbing in your tests:\n\n```swift\noverride func tearDown() {\n  Hippolyte.shared.stop()\n  super.tearDown()\n}\n```\n\nYou can configure your stub response in a number of ways, such as having it return different HTTP status codes, headers, and errors.\n\n## License\n\nHippolyte is released under the MIT license. See LICENSE for details\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjangorman%2Fhippolyte","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjangorman%2Fhippolyte","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjangorman%2Fhippolyte/lists"}