A minimal method stub for Swift.
import Stubber
final class StubUserService: UserServiceProtocol, Stub {
func follow(userID: Int) -> String {
return stubbed(follow, args: userID)
}
func edit(userID: Int, name: String) -> Bool {
return stubbed(edit, args: (userID, name))
}
}
func testMethodCall() {
let userService = StubUserService()
userService.stub(userService.follow) { userID in "stub-\(userID)" } // stub
userService.follow(userID: 123) // call
XCTAssertEqual(userService.executions(userService.follow).count, 1)
XCTAssertEqual(userService.executions(userService.follow)[0].arguments, 123)
XCTAssertEqual(userService.executions(userService.follow)[0].result, "stub-123")
}
pod 'Stubber'
Stubber is under MIT license. See the LICENSE for more info.