Latest | 0.1.4 |
---|---|
Homepage | https://github.com/lvsti/NimbleMockSix |
License | MIT |
Platforms | ios 8.4, osx 10.10, tvos 9.2 |
Dependencies | MockSix, Nimble |
Frameworks | MockSix, Nimble, XCTest* |
Authors |
Teaser
With NimbleMockSix, you can easily make expectations on method invocations on MockSix mock objects. Suppose you have the following mock already in place (for details, see the MockSix documentation):
// original interface to mock
protocol MyClassProtocol {
func myFunc(string: String, number: Double) -> [Int]
}
// original implementation
class MyClass: MyClassProtocol {
func myFunc(string: String, number: Double) -> [Int] {
// ... whatever ...
return [1, 2, 3]
}
}
// mock implementation
class MockMyClass: MyClassProtocol, Mock {
enum Methods: Int {
case myFunc
}
typealias MockMethod = Methods
func myFunc(string: String, number: Double) -> [Int] {
return registerInvocation(for: .myFunc,
args: string, number
andReturn: [])
}
}
To test for the invocation count of a method:
// given
let myMock = MockMyClass()
myMock.stub(.myFunc, andReturn: [42])
// when
myMock.myFunc(string: "aaa", number: 3.14)
myMock.myFunc(string: "bbb", number: 6.28)
// then
expect(myMock).to(receive(.myFunc, times: 2)) // --> passes
To test the arguments of an invocation:
// given
let myMock = MockMyClass()
myMock.stub(.myFunc, andReturn: [42])
// when
myMock.myFunc(string: "aaa", number: 3.14)
expect(myMock).to(receive(.myFunc, with: [
theValue("aaa"),
any()
])) // --> passes
expect(myMock).to(receive(.myFunc, with: [
any(of: ["bbb", "ccc"]),
any { x in x >= 3.0 && x < 4.0 }
])) // --> fails
But there is more!
Currently implemented matchers:
- just invocation count constraints:
receive(_:times:)
,receive(_:atLeastTimes:)
,receive(_:atMostTimes:)
- invocation count AND argument constraints:
receive(_:times:with:)
,receive(_:atLeastTimes:with:)
,receive(_:atMostTimes:with:)
:
Currently implemented argument verifiers:
theValue(_:)
: argument matches the given valuenilValue()
: argument is nilany()
: argument matches anything (always passes)any(of:)
: argument matches any of the values in the arrayany(passing:)
: argument makes the predicate true
Requirements
To build: Swift 4
To use: macOS 10.10+, iOS 8.4+, tvOS 9.2+, Linux
Installation
Via Cocoapods: add the following line to your Podfile:
pod 'NimbleMockSix'
Via Carthage: add the following lines to your Cartfile (or Cartfile.private):
github "lvsti/NimbleMockSix"
github "Quick/Quick"
Via the Swift Package Manager: add it to the dependencies in your Package.swift:
let package = Package(
name: "MyAwesomeApp",
dependencies: [
.package(url: "https://github.com/lvsti/NimbleMockSix", from: "0.1.3"),
.package(url: "https://github.com/Quick/Quick", from: "1.2.0"),
// ... other dependencies ...
]
)
License
NimbleMockSix is released under the MIT license.
Latest podspec
{ "name": "NimbleMockSix", "version": "0.1.4", "license": "MIT", "summary": "Nimble matchers for MockSix", "description": "With NimbleMockSix, you can easily make expectations on method invocations on MockSix mock objects in Swift.", "homepage": "https://github.com/lvsti/NimbleMockSix", "social_media_url": "https://twitter.com/cocoagrinder", "authors": { "Tamas Lustyik": "[email protected]" }, "source": { "git": "https://github.com/lvsti/NimbleMockSix.git", "tag": "v0.1.4" }, "platforms": { "ios": "8.4", "osx": "10.10", "tvos": "9.2" }, "source_files": "Sources/NimbleMockSix/*.{swift,h}", "public_header_files": "Sources/NimbleMockSix/NimbleMockSix.h", "dependencies": { "MockSix": [ "0.1.7" ], "Nimble": [ "~> 7.0" ] }, "frameworks": [ "MockSix", "Nimble" ], "weak_frameworks": "XCTest", "pod_target_xcconfig": { "ENABLE_BITCODE": "NO", "OTHER_LDFLAGS": "-weak-lswiftXCTest", "FRAMEWORK_SEARCH_PATHS": "$(inherited) "$(PLATFORM_DIR)/Developer/Library/Frameworks"" }, "pushed_with_swift_version": "3.1" }
Wed, 17 Jan 2018 13:00:51 +0000