{"id":17648826,"url":"https://github.com/wvteijlingen/swift-network-mocker","last_synced_at":"2026-02-11T21:31:15.233Z","repository":{"id":44560863,"uuid":"417852696","full_name":"wvteijlingen/swift-network-mocker","owner":"wvteijlingen","description":"Speed up development and testing by adding an autogenerated network stubbing panel to your app.","archived":false,"fork":false,"pushed_at":"2022-11-08T13:48:33.000Z","size":156,"stargazers_count":4,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-07T06:04:23.902Z","etag":null,"topics":["mocking","moya","network-stubbing","networking","stubbing","testing"],"latest_commit_sha":null,"homepage":"","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/wvteijlingen.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-10-16T14:29:27.000Z","updated_at":"2022-07-13T13:09:50.000Z","dependencies_parsed_at":"2023-01-21T08:45:17.523Z","dependency_job_id":null,"html_url":"https://github.com/wvteijlingen/swift-network-mocker","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/wvteijlingen/swift-network-mocker","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wvteijlingen%2Fswift-network-mocker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wvteijlingen%2Fswift-network-mocker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wvteijlingen%2Fswift-network-mocker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wvteijlingen%2Fswift-network-mocker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wvteijlingen","download_url":"https://codeload.github.com/wvteijlingen/swift-network-mocker/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wvteijlingen%2Fswift-network-mocker/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29345483,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-11T20:11:40.865Z","status":"ssl_error","status_checked_at":"2026-02-11T20:10:41.637Z","response_time":97,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["mocking","moya","network-stubbing","networking","stubbing","testing"],"created_at":"2024-10-23T11:21:02.163Z","updated_at":"2026-02-11T21:31:15.216Z","avatar_url":"https://github.com/wvteijlingen.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cimg src=\"./moya-stubber.png\" width=\"150\" height=\"150\"/\u003e\n\n# moya-stubber: supercharged stubbing for Moya\n\nMoya-stubber speeds up development and testing by adding a network stubbing screen to your app.\n\nWant to add a stub response? It's as easy as creating a new JSON file in your project repository. Moya Stubber will automatically find it and make it activatable for stubbing.\n\nMoya Stubber will:\n\n- Provide an autogenerated view controller to activate and deactivate stubs at runtime.\n- Allow you to configure multiple stubbed responses per endpoint, so you can easilty test your code in multiple scenarios.\n- Use regular files for stubbed responses (json, xml, or any other filetype).\n- Allow you to activate stubs programatically to simulate network responses in unit tests.\n- Define a clear hierarchical structure for your stubs.\n\n**Example of autogenerated stubbing panel**\n\n![index](https://user-images.githubusercontent.com/1460535/145678378-c67cf154-4858-4700-b1cc-ef0223e99cb8.png)\n![detail](https://user-images.githubusercontent.com/1460535/145678383-4c55e83e-399a-4b55-956d-a871fde2f4a8.png)\n\n## Installation\n\n**Swift Package Manager**\n\n```swift\n.package(url: \"https://github.com/wvteijlingen/moya-stubber.git\", .upToNextMajor(from: \"0.2.0\"))\n```\n\n**CocoaPods**\n\n```ruby\npod \"moya-stubber\", :git =\u003e \"https://github.com/wvteijlingen/moya-stubber.git\"\n```\n\n**Manually**\n\nCopy `MoyaStubber.swift` and `MoyaStubberViewController.swift` to your project.\n\n## Usage\n\n1. Create a bundle containing your JSON stub responses. See [Stubs.bundle file structure](#Stubs-bundle-file-structure).\n2. Configure your MoyaProvider to use the stubber by adding an `endpointClosure` and `stubClosure`:\n\n```swift\nlet stubsBundle = Bundle(url: Bundle.main.bundleURL.appendingPathComponent(\"Stubs.bundle\"))!\n\ntry! MoyaStubber.shared.setStubsBundle(stubsBundle)\n\nMoyaProvider(\n    endpointClosure: MoyaStubber.shared.endpointClosure,\n    stubClosure: MoyaStubber.shared.stubClosure\n)\n```\n\n3. Add the stubbing view controller:\n\n```swift\nlet viewController = MoyaStubberViewController(stubber: MoyaStubber.shared)\npresent(viewController, animated: true)\n```\n\n## Stubs bundle file structure\n\nMoyaStubber expects the Stubs.bundle to have the following structure:\n\n1. Every endpoint that you want to stub must be a subdirectory of the bundle.\n   Its name must match a case in your `Moya.TargetType` enum.\n1. Within each endpoint directory you can place multiple stubs with the following naming pattern `[name].[statusCode].[extension]`.\n1. Stubs that are placed in the root of the bundle will be available to all endpoints.\n   You can use this for generic responses such as internal server errors.\n\n### Example\n\nIf your Moya target looks like this…\n\n```swift\nenum MyMoyaTarget: TargetType {\n  case getUser\n  case getUserAvatar\n  case deleteUser\n}\n```\n\n…your stubs bundle can be structured like this:\n\n```\nStubs.bundle\n  | serverError.500.json\n  | notFound.404.json\n  |\n  | getUser\n  |   | ok.200.json\n  |\n  | getUserAvatar\n  |   | ok.200.jpg\n  |\n  | deleteUser\n  |   | ok.204.json\n```\n\n## Advanced\n\n### Exclude stubs from release builds\n\nIf you don't want to include your stubs in release builds, you can exclude them from your target\nand use an Xcode Build Phase to include it only when needed. The exact command will depend on the project setup.\n\n**Example**\n\n```bash\nif [ \"${CONFIGURATION}\" != \"Release\" ]; then\n  rsync --recursive --delete \"${SRCROOT}/MyProject/Stubs.bundle\" \"${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.app\"\nfi\n```\n\n### Enable stubs programatically\n\nYou can also enable or disable stubs programatically:\n\n```swift\nstubber.activate(stubNamed: \"ok.200.json\", forEndpointNamed: \"getUser\")\nstubber.deactivateStub(forEndpointNamed: \"getUser\")\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwvteijlingen%2Fswift-network-mocker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwvteijlingen%2Fswift-network-mocker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwvteijlingen%2Fswift-network-mocker/lists"}