Latest 1.3.1
Homepage https://github.com/devxoul/Stubber
License MIT
Platforms ios 8.0, osx 10.11, tvos 9.0, watchos 2.0
Frameworks Foundation
Authors

Swift
CocoaPods
Build Status
Codecov

A minimal method stub for Swift.

At a Glance

import Stubber

final 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.

 func request(path: String, completion: @escaping (Result) -> Void) {
-  Stubber.invoke(request, args: (path, completion))
+  Stubber.invoke(request, args: escaping(path, completion))
 }

Installation

pod 'Stubber'

License

Stubber is under MIT license. See the LICENSE for more info.

Latest podspec

{
    "name": "Stubber",
    "version": "1.3.1",
    "summary": "A minimal method stub for Swift",
    "homepage": "https://github.com/devxoul/Stubber",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Suyeol Jeon": "[email protected]"
    },
    "source": {
        "git": "https://github.com/devxoul/Stubber.git",
        "tag": "1.3.1"
    },
    "source_files": "Sources/**/*.{swift,h,m}",
    "frameworks": "Foundation",
    "platforms": {
        "ios": "8.0",
        "osx": "10.11",
        "tvos": "9.0",
        "watchos": "2.0"
    }
}

Pin It on Pinterest

Share This