Update comments.

This commit is contained in:
Filip Dolník 2016-07-05 21:44:41 +02:00
parent 8985856670
commit 0855fa6c26
10 changed files with 31 additions and 27 deletions

View File

@ -121,19 +121,19 @@ Note: It is currently possible for the subbing object to escape from the closure
After calling the `when` function you can specify what to do next with following methods:
```Swift
/// Invoke `implementation` when invoked.
/// Invokes `implementation` when invoked.
then(implementation: IN throws -> OUT)
/// Return `output` when invoked.
/// Returns `output` when invoked.
thenReturn(output: OUT, _ outputs: OUT...)
/// Throw `error` when invoked.
/// Throws `error` when invoked.
thenThrow(error: ErrorType, _ outputs: OUT...)
/// Invoke real implementation when invoked.
/// Invokes real implementation when invoked.
thenCallRealImplementation()
/// Do nothing when invoked.
/// Does nothing when invoked.
thenDoNothing()
```
@ -311,13 +311,13 @@ As with `Matchable` you can chain `CallMatcher` with methods `or` and `and`. But
Following functions are used to reset stubbing and/or invocations on mocks.
```Swift
/// Clear all invocations and stubs of mocks.
/// Clears all invocations and stubs of mocks.
reset<M: Mock>(mocks: M...)
/// Clear all stubs of mocks.
/// Clears all stubs of mocks.
clearStubs<M: Mock>(mocks: M...)
/// Clear all invocations of mocks.
/// Clears all invocations of mocks.
clearInvocations<M: Mock>(mocks: M...)
```

View File

@ -6,36 +6,38 @@
// Copyright © 2016 Brightify. All rights reserved.
//
/// Start the stubbing for the given mock. Can be used multiple times.
/// Starts the stubbing for the given mock. Can be used multiple times.
public func stub<M: Mock>(mock: M, @noescape block: M.Stubbing -> Void) {
block(mock.getStubbingProxy())
}
/// Used in stubbing. Currently only returns passed function but this may change in the future so it is not recommended to omit it.
@warn_unused_result
public func when<F>(function: F) -> F {
return function
}
/// Creates object used for verification of calls.
@warn_unused_result
public func verify<M: Mock>(mock: M, _ callMatcher: CallMatcher = times(1), file: StaticString = #file, line: UInt = #line) -> M.Verification {
return mock.getVerificationProxy(callMatcher, sourceLocation: (file, line))
public func verify<M: Mock>(mock: M, _ callMatcher: CallMatcher = times(1), sourceLocation: SourceLocation = (#file, #line)) -> M.Verification {
return mock.getVerificationProxy(callMatcher, sourceLocation: sourceLocation)
}
/// Clear all invocations and stubs of mocks.
/// Clears all invocations and stubs of mocks.
public func reset<M: Mock>(mocks: M...) {
mocks.forEach { mock in
mock.manager.reset()
}
}
/// Clear all stubs of mocks.
/// Clears all stubs of mocks.
public func clearStubs<M: Mock>(mocks: M...) {
mocks.forEach { mock in
mock.manager.clearStubs()
}
}
/// Clear all invocations of mocks.
/// Clears all invocations of mocks.
public func clearInvocations<M: Mock>(mocks: M...) {
mocks.forEach { mock in
mock.manager.clearInvocations()
@ -43,8 +45,8 @@ public func clearInvocations<M: Mock>(mocks: M...) {
}
/// Checks if there are no more uverified calls.
public func verifyNoMoreInteractions<M: Mock>(mocks: M..., file: StaticString = #file, line: UInt = #line) {
public func verifyNoMoreInteractions<M: Mock>(mocks: M..., sourceLocation: SourceLocation = (#file, #line)) {
mocks.forEach { mock in
mock.manager.verifyNoMoreInteractions((file, line))
mock.manager.verifyNoMoreInteractions(sourceLocation)
}
}

View File

@ -6,6 +6,7 @@
// Copyright © 2016 Brightify. All rights reserved.
//
/// CallMatcher is used in verification to assert how many times was the call made. It can also be used to do different asserts on stub calls matched with parameter matchers.
public struct CallMatcher {
private let matchesFunction: [StubCall] throws -> Bool

View File

@ -6,6 +6,7 @@
// Copyright © 2016 Brightify. All rights reserved.
//
/// ParameterMatcher matches parameters of methods in stubbing and verification.
public struct ParameterMatcher<T>: Matchable {
private let matchesFunction: T throws -> Bool

View File

@ -9,7 +9,7 @@
import XCTest
public class MockManager {
static var fail: (message: String, file: StaticString, line: UInt) -> () = XCTFail
static var fail: (message: String, sourceLocation: SourceLocation) -> () = { XCTFail($0, file: $1.file, line: $1.line) }
private var stubs: [Stub] = []
private var stubCalls: [StubCall] = []
@ -85,7 +85,7 @@ public class MockManager {
if callMatcher.matches(calls) == false {
let description = Description()
MockManager.fail(message: description.description, file: sourceLocation.file, line: sourceLocation.line)
MockManager.fail(message: description.description, sourceLocation: sourceLocation)
}
return __DoNotUse()
}
@ -107,13 +107,13 @@ public class MockManager {
func verifyNoMoreInteractions(sourceLocation: SourceLocation) {
if unverifiedStubCallsIndexes.isEmpty == false {
let unverifiedCalls = unverifiedStubCallsIndexes.map { stubCalls[$0] }.map { String($0) }.joinWithSeparator(", ")
MockManager.fail(message: "Found unverified call(s): " + unverifiedCalls, file: sourceLocation.file, line: sourceLocation.line)
MockManager.fail(message: "Found unverified call(s): " + unverifiedCalls, sourceLocation: sourceLocation)
}
}
@noreturn
private func failAndCrash(message: String, file: StaticString = #file, line: UInt = #line) {
MockManager.fail(message: message, file: file, line: line)
private func failAndCrash(message: String, sourceLocation: SourceLocation = (#file, #line)) {
MockManager.fail(message: message, sourceLocation: sourceLocation)
fatalError(message)
}
}

View File

@ -7,7 +7,7 @@
//
public protocol StubFunctionThenCallRealImplementationTrait: BaseStubFunctionTrait {
/// Invoke real implementation when invoked.
/// Invokes real implementation when invoked.
func thenCallRealImplementation() -> Self
}

View File

@ -7,7 +7,7 @@
//
public protocol StubFunctionThenDoNothingTrait: BaseStubFunctionTrait {
/// Do nothing when invoked.
/// Does nothing when invoked.
func thenDoNothing() -> Self
}

View File

@ -7,7 +7,7 @@
//
public protocol StubFunctionThenReturnTrait: BaseStubFunctionTrait {
/// Return `output` when invoked.
/// Returns `output` when invoked.
func thenReturn(output: OUT, _ outputs: OUT...) -> Self
}

View File

@ -7,7 +7,7 @@
//
public protocol StubFunctionThenThrowTrait: BaseStubFunctionTrait {
/// Throw `error` when invoked.
/// Throws `error` when invoked.
func thenThrow(error: ErrorType, _ errors: ErrorType...) -> Self
}

View File

@ -7,7 +7,7 @@
//
public protocol StubFunctionThenTrait: BaseStubFunctionTrait {
/// Invoke `implementation` when invoked.
/// Invokes `implementation` when invoked.
func then(implementation: IN -> OUT) -> Self
}