{"id":27399876,"url":"https://github.com/tattn/replacer","last_synced_at":"2025-10-24T07:42:16.815Z","repository":{"id":15275521,"uuid":"77810847","full_name":"tattn/Replacer","owner":"tattn","description":"An easy-to-use library to stub HTTP requests using URLSession and to swizzle methods","archived":false,"fork":false,"pushed_at":"2022-07-22T16:19:07.000Z","size":49,"stargazers_count":30,"open_issues_count":0,"forks_count":5,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-10-10T19:16:29.132Z","etag":null,"topics":["ios","methodswizzling","stub","swift","urlsession","xctest"],"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/tattn.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}},"created_at":"2017-01-02T04:31:35.000Z","updated_at":"2022-04-16T15:06:39.000Z","dependencies_parsed_at":"2022-08-07T08:01:01.841Z","dependency_job_id":null,"html_url":"https://github.com/tattn/Replacer","commit_stats":null,"previous_names":["tattn/mokei"],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/tattn/Replacer","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tattn%2FReplacer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tattn%2FReplacer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tattn%2FReplacer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tattn%2FReplacer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tattn","download_url":"https://codeload.github.com/tattn/Replacer/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tattn%2FReplacer/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":280761850,"owners_count":26386245,"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","status":"online","status_checked_at":"2025-10-24T02:00:06.418Z","response_time":73,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["ios","methodswizzling","stub","swift","urlsession","xctest"],"created_at":"2025-04-14T03:24:21.592Z","updated_at":"2025-10-24T07:42:16.784Z","avatar_url":"https://github.com/tattn.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"Replacer\n===\n\n[![Build Status](https://travis-ci.org/tattn/Replacer.svg?branch=master)](https://travis-ci.org/tattn/Replacer)\n[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)\n[![Version](https://img.shields.io/cocoapods/v/Replacer.svg)](http://cocoapods.org/pods/Replacer)\n[![Platform](https://img.shields.io/cocoapods/p/Replacer.svg)](http://cocoapods.org/pods/Replacer)\n[![License](https://img.shields.io/cocoapods/l/Replacer.svg)](http://cocoapods.org/pods/Replacer)\n[![Swift Version](https://img.shields.io/badge/Swift-5-F16D39.svg)](https://developer.apple.com/swift)\n\n\nReplacer is an easy-to-use library to stub HTTP requests and to swizzle methods.\n\nSpecifically, URLSession's response can be replaced with any JSON, Data, and so on....  \nIt uses **method chaining** to set stubs up.\n\n# How to use\n\n## Stub HTTP Request\n\n### XCTest\n\n```swift\nimport Replacer\nimport TestReplacer \n\nclass SampleTests: XCTestCase {\n    func testJSONFile() {\n        // register a stub\n        self.urlStub.url(\"echo.jsontest.com\").json([\"test\": \"data\"])\n        \n        // load sample.json \u0026 register a stub.\n        self.urlStub.json(filename: \"sample\")\n\n        let expectation = self.expectation(description: \"\")\n        \n        let url = URL(string: \"http://echo.jsontest.com/key/value/one/two\")!\n        URLSession(configuration: .default).dataTask(with: url) { data, _, _ in\n            let json = try! JSONSerialization.jsonObject(with: data!, options: .allowFragments) as! [String: String]\n            XCTAssert(json[\"test\"] == \"data\")\n            expectation.fulfill()\n        }.resume()\n\n        self.waitForExpectations(timeout: 0.02, handler: nil)\n    }\n}\n```\n\n### Quick \u0026 Alamofire\n\n```swift\nclass SampleSpecs: QuickSpec {\n    override func spec() {\n        describe(\"Quick compatibility test\") {\n            context(\"using JSON file\") {\n                beforeEach() {\n                    // wait for 1.5s\n                    self.urlStub.url(\"echo.jsontest.com/[a-z]+/.*\")\n                        .httpMethod(.post)\n                        .json([\"test\": \"data\"])\n                        .delay(1.5)\n                }\n\n                it(\"returns mock data\") {\n                    var json: [String: String]?\n\n                    Alamofire.request(\"http://echo.jsontest.com/key/value/one/two\", method: .post).responseJSON { response in\n                        json = response.result.value as? [String: String]\n                    }\n\n\t\t\t\t\t// SessionManager is also OK.\n\t\t\t\t\t// SessionManager.default.request(\"http://echo.jsontest.com/key/value/one/two\").responseJSON { _ in }\n\n                    expect(json?[\"test\"]).toEventually(equal(\"data\"))\n                }\n            }\n        }\n    }\n}\n```\n\n## Method Swizzling\n\n```swift\nimport UIKit\nimport Replacer\n\n@UIApplicationMain\nclass AppDelegate: UIResponder, UIApplicationDelegate {\n\n    var window: UIWindow?\n\n    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -\u003e Bool {\n\n        Replacer.replaceInstance(#selector(UIViewController.viewWillAppear(_:)),\n                                 of: UIViewController.self,\n                                 with: #selector(UIViewController.orig_viewWillAppear(_:)),\n                                 of: UIViewController.self)\n\n        return true\n    }\n}\n\nextension UIViewController {\n    func orig_viewWillAppear(_ animated: Bool) {\n        orig_viewWillAppear(animated)\n\n        print(\"swizzled\")\n    }\n}\n\n```\n\n# Installation\n\n## Carthage\n\n```ruby\ngithub \"tattn/Replacer\"\n```\n\n## CocoaPods\n\n```ruby\npod 'Replacer'\n```\n\n# Documentation\n\n- [Stub Reference](https://github.com/tattn/Replacer/blob/master/Documentations/Reference.md)\n\n# Contributing\n\n1. Fork it!\n2. Create your feature branch: `git checkout -b my-new-feature`\n3. Commit your changes: `git commit -am 'Add some feature'`\n4. Push to the branch: `git push origin my-new-feature`\n5. Submit a pull request :D\n\n# License\n\nReplacer is released under the MIT license. See LICENSE for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftattn%2Freplacer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftattn%2Freplacer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftattn%2Freplacer/lists"}