https://github.com/devxoul/stubber
A minimal method stub for Swift
https://github.com/devxoul/stubber
stub swift
Last synced: 3 months ago
JSON representation
A minimal method stub for Swift
- Host: GitHub
- URL: https://github.com/devxoul/stubber
- Owner: devxoul
- License: mit
- Created: 2017-07-27T06:21:25.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2020-10-28T06:11:02.000Z (over 4 years ago)
- Last Synced: 2025-02-27T18:13:45.510Z (4 months ago)
- Topics: stub, swift
- Language: Swift
- Homepage:
- Size: 36.1 KB
- Stars: 89
- Watchers: 6
- Forks: 12
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Stubber

[](https://cocoapods.org/pods/Stubber)
[](https://travis-ci.org/devxoul/Stubber)
[](https://codecov.io/gh/devxoul/Stubber)A minimal method stub for Swift.
## At a Glance
```swift
import Stubberfinal class StubUserService: UserServiceProtocol {
func follow(userID: Int) -> String {
return Stubber.invoke(follow, args: userID)
}func edit(userID: Int, name: String) -> Bool {
return Stubber.invoke(edit, args: (userID, name))
}
}func testMethodCall() {
// given
let userService = StubUserService()
Stubber.register(userService.follow) { userID in "stub-\(userID)" } // stub
// when
userService.follow(userID: 123) // call
// then
XCTAssertEqual(Stubber.executions(userService.follow).count, 1)
XCTAssertEqual(Stubber.executions(userService.follow)[0].arguments, 123)
XCTAssertEqual(Stubber.executions(userService.follow)[0].result, "stub-123")
}
```## Escaping Parameters
When a function contains an escaped parameter, use `escaping()` on arguments.
```diff
func request(path: String, completion: @escaping (Result) -> Void) {
- Stubber.invoke(request, args: (path, completion))
+ Stubber.invoke(request, args: escaping(path, completion))
}
```## Installation
```ruby
pod 'Stubber'
```## License
Stubber is under MIT license. See the [LICENSE](LICENSE) for more info.