{"id":16685107,"url":"https://github.com/ceek/check","last_synced_at":"2025-04-09T23:52:16.134Z","repository":{"id":56905833,"uuid":"64408975","full_name":"ceeK/Check","owner":"ceeK","description":"A Swift mocking library to create concise and DRY mocks.","archived":false,"fork":false,"pushed_at":"2016-07-31T20:27:48.000Z","size":12,"stargazers_count":7,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-04-09T23:52:11.196Z","etag":null,"topics":[],"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/ceeK.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":"2016-07-28T15:55:47.000Z","updated_at":"2017-05-04T11:58:28.000Z","dependencies_parsed_at":"2022-08-21T03:50:07.704Z","dependency_job_id":null,"html_url":"https://github.com/ceeK/Check","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ceeK%2FCheck","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ceeK%2FCheck/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ceeK%2FCheck/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ceeK%2FCheck/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ceeK","download_url":"https://codeload.github.com/ceeK/Check/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248131454,"owners_count":21052819,"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":[],"created_at":"2024-10-12T14:46:03.933Z","updated_at":"2025-04-09T23:52:16.110Z","avatar_url":"https://github.com/ceeK.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Check\n\n[![Version](https://img.shields.io/cocoapods/v/Check.svg?style=flat)](http://cocoapods.org/pods/Check) [![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)\n [![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/hyperium/hyper/master/LICENSE)\n\nCheck is a Swift mock library for creating concise, [DRY](https://en.wikipedia.org/wiki/Don%27t_repeat_yourself) mocks.\n\nCheck has been designed to work when using protocols to inject dependencies. \n\n## Creating a mock\n\nYou can create a mock by subclassing `Mock`, conforming to the protocol you want to mock, and implementing either `stub()` or `spy()` in your function implementations.\n\n```swift\nclass MockDolphin: Mock, Dolphin {\n\t\n\tfunc click() -\u003e String {\n\t\treturn stub()\n\t}\n\n\tfunc jump(numberOfTimes: Int) -\u003e String {\n\t\treturn stub(args: [numberOfTimes])\n\t}\n\n\tfunc swim() {\n\t\tspy()\n\t}\n\n\tfunc dive(handler: (depth: Float, success: Bool) -\u003e ()) {\n\t\tguard let stub: (Float, Bool) = stub() else { return }\n\t\thandler(depth: stub.0, success: stub.1)\n\t}\n\n}\n```\n\n## Using the mock in your tests \n\nTo stub a response in your test class:\n\n```swift\n\tmockDolphin.responses[\"click\"] = \"Click!\"\n\tmockDolphin.responses[\"dive\"] = (5.4, true)\n```\n\nTo verify a method call:\n\n```swift\n\tmockDolphin.checkMethodCall(named: \"swim\")\n```\n\nTo verify an argument:\n\n```swift\n\tmockDolphin.checkArguments(method: \"jump\", argument: 3)\n```\n\n## More detailed usage\n\n#### Stubbing a method\n\nTo enable the stubbing of a method's response from the test spec, simply return `stub()` in the call:\n\n```swift\n\tfunc click() -\u003e String {\n\t\treturn stub()\n\t}\n```\n\nTo be able to track the arguments passed into a function, record which arguments you wish to track:\n\n```swift\n\tfunc jump(numberOfTimes: Int) -\u003e String {\n\t\treturn stub(args: [numberOfTimes])\n\t}\n```\n\n#### Stubbing a variable\n\nIt's also possible to stub the response of a variable. To get around the Swift type system, you may need to force unwrap the response of `stub()`: \n\n```swift\n\tvar dolphinGender: Gender {\n\t\treturn stub()!\n\t}\n\n\tvar isDolphinSwimming: Bool  {\n        get {\n            return stub()!\n        }\n        set {}\n    }\n```\n\n#### Stubbing a method with a closure\n\n```swift\n\tfunc dive(handler: (depth: Float, success: Bool) -\u003e ()) {\n\t\tguard let stub: (Float, Bool) = stub() else { return }\n\t\thandler(depth: stub.0, success: stub.1)\n\t}\n```\n\n#### Spying on a method\n\nIf you don't need to stub a method response, you can show your intent by instead calling `spy()` in the function implementation:\n\n```swift\n\tfunc swim() {\n\t\tspy()\n\t}\n```\n\n## Installation\n\nCheck is available through CocoaPods and Carthage. \n\n### Cocoapods\n\nTo install, simply add the following line to your podfile:\n\n```ruby\npod \"Check\"\n```\n\nThen run `pod install`\n\n### Carthage\n\nAdd the `ceek/Check` project to your [Cartfile](https://github.com/Carthage/Carthage/blob/master/Documentation/Artifacts.md#cartfile)\n\n```ruby\ngithub \"ceeK/Check\"\n```\n\nThen run `carthage update`\n\n## License\nThe MIT License (MIT)\n\nCopyright (c) 2016 Chris Howell\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fceek%2Fcheck","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fceek%2Fcheck","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fceek%2Fcheck/lists"}