From 0855fa6c268e9f443f2a38b6d0d94e36b0a0ee76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20Dolni=CC=81k?= Date: Tue, 5 Jul 2016 21:44:41 +0200 Subject: [PATCH] Update comments. --- README.md | 16 ++++++++-------- Source/CuckooFunctions.swift | 18 ++++++++++-------- Source/Matching/CallMatcher.swift | 3 ++- Source/Matching/ParameterMatcher.swift | 1 + Source/MockManager.swift | 10 +++++----- ...nctionThenCallRealImplementationTrait.swift | 2 +- .../Trait/StubFunctionThenDoNothingTrait.swift | 2 +- .../Trait/StubFunctionThenReturnTrait.swift | 2 +- .../Trait/StubFunctionThenThrowTrait.swift | 2 +- .../Trait/StubFunctionThenTrait.swift | 2 +- 10 files changed, 31 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index 4843a65..80ea8c7 100644 --- a/README.md +++ b/README.md @@ -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(mocks: M...) -/// Clear all stubs of mocks. +/// Clears all stubs of mocks. clearStubs(mocks: M...) -/// Clear all invocations of mocks. +/// Clears all invocations of mocks. clearInvocations(mocks: M...) ``` diff --git a/Source/CuckooFunctions.swift b/Source/CuckooFunctions.swift index 0ef5495..fc4a81c 100644 --- a/Source/CuckooFunctions.swift +++ b/Source/CuckooFunctions.swift @@ -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(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(function: F) -> F { return function } +/// Creates object used for verification of calls. @warn_unused_result -public func verify(mock: M, _ callMatcher: CallMatcher = times(1), file: StaticString = #file, line: UInt = #line) -> M.Verification { - return mock.getVerificationProxy(callMatcher, sourceLocation: (file, line)) +public func verify(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(mocks: M...) { mocks.forEach { mock in mock.manager.reset() } } -/// Clear all stubs of mocks. +/// Clears all stubs of mocks. public func clearStubs(mocks: M...) { mocks.forEach { mock in mock.manager.clearStubs() } } -/// Clear all invocations of mocks. +/// Clears all invocations of mocks. public func clearInvocations(mocks: M...) { mocks.forEach { mock in mock.manager.clearInvocations() @@ -43,8 +45,8 @@ public func clearInvocations(mocks: M...) { } /// Checks if there are no more uverified calls. -public func verifyNoMoreInteractions(mocks: M..., file: StaticString = #file, line: UInt = #line) { +public func verifyNoMoreInteractions(mocks: M..., sourceLocation: SourceLocation = (#file, #line)) { mocks.forEach { mock in - mock.manager.verifyNoMoreInteractions((file, line)) + mock.manager.verifyNoMoreInteractions(sourceLocation) } } \ No newline at end of file diff --git a/Source/Matching/CallMatcher.swift b/Source/Matching/CallMatcher.swift index f522e06..cc55169 100644 --- a/Source/Matching/CallMatcher.swift +++ b/Source/Matching/CallMatcher.swift @@ -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 @@ -18,7 +19,7 @@ public struct CallMatcher { return compareCallsFunction(expected: numberOfExpectedCalls, actual: $0.count) } } - + public func matches(calls: [StubCall]) -> Bool { do { return try matchesFunction(calls) diff --git a/Source/Matching/ParameterMatcher.swift b/Source/Matching/ParameterMatcher.swift index 761cd5e..8678767 100644 --- a/Source/Matching/ParameterMatcher.swift +++ b/Source/Matching/ParameterMatcher.swift @@ -6,6 +6,7 @@ // Copyright © 2016 Brightify. All rights reserved. // +/// ParameterMatcher matches parameters of methods in stubbing and verification. public struct ParameterMatcher: Matchable { private let matchesFunction: T throws -> Bool diff --git a/Source/MockManager.swift b/Source/MockManager.swift index 316a009..7fabee5 100644 --- a/Source/MockManager.swift +++ b/Source/MockManager.swift @@ -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) } } diff --git a/Source/Stubbing/StubFunction/Trait/StubFunctionThenCallRealImplementationTrait.swift b/Source/Stubbing/StubFunction/Trait/StubFunctionThenCallRealImplementationTrait.swift index c3794ec..e6ad728 100644 --- a/Source/Stubbing/StubFunction/Trait/StubFunctionThenCallRealImplementationTrait.swift +++ b/Source/Stubbing/StubFunction/Trait/StubFunctionThenCallRealImplementationTrait.swift @@ -7,7 +7,7 @@ // public protocol StubFunctionThenCallRealImplementationTrait: BaseStubFunctionTrait { - /// Invoke real implementation when invoked. + /// Invokes real implementation when invoked. func thenCallRealImplementation() -> Self } diff --git a/Source/Stubbing/StubFunction/Trait/StubFunctionThenDoNothingTrait.swift b/Source/Stubbing/StubFunction/Trait/StubFunctionThenDoNothingTrait.swift index 8b14075..7d14c70 100644 --- a/Source/Stubbing/StubFunction/Trait/StubFunctionThenDoNothingTrait.swift +++ b/Source/Stubbing/StubFunction/Trait/StubFunctionThenDoNothingTrait.swift @@ -7,7 +7,7 @@ // public protocol StubFunctionThenDoNothingTrait: BaseStubFunctionTrait { - /// Do nothing when invoked. + /// Does nothing when invoked. func thenDoNothing() -> Self } diff --git a/Source/Stubbing/StubFunction/Trait/StubFunctionThenReturnTrait.swift b/Source/Stubbing/StubFunction/Trait/StubFunctionThenReturnTrait.swift index d925e3a..c4e6afd 100644 --- a/Source/Stubbing/StubFunction/Trait/StubFunctionThenReturnTrait.swift +++ b/Source/Stubbing/StubFunction/Trait/StubFunctionThenReturnTrait.swift @@ -7,7 +7,7 @@ // public protocol StubFunctionThenReturnTrait: BaseStubFunctionTrait { - /// Return `output` when invoked. + /// Returns `output` when invoked. func thenReturn(output: OUT, _ outputs: OUT...) -> Self } diff --git a/Source/Stubbing/StubFunction/Trait/StubFunctionThenThrowTrait.swift b/Source/Stubbing/StubFunction/Trait/StubFunctionThenThrowTrait.swift index 8fb5eae..23b1d31 100644 --- a/Source/Stubbing/StubFunction/Trait/StubFunctionThenThrowTrait.swift +++ b/Source/Stubbing/StubFunction/Trait/StubFunctionThenThrowTrait.swift @@ -7,7 +7,7 @@ // public protocol StubFunctionThenThrowTrait: BaseStubFunctionTrait { - /// Throw `error` when invoked. + /// Throws `error` when invoked. func thenThrow(error: ErrorType, _ errors: ErrorType...) -> Self } diff --git a/Source/Stubbing/StubFunction/Trait/StubFunctionThenTrait.swift b/Source/Stubbing/StubFunction/Trait/StubFunctionThenTrait.swift index 729299a..eb788a3 100644 --- a/Source/Stubbing/StubFunction/Trait/StubFunctionThenTrait.swift +++ b/Source/Stubbing/StubFunction/Trait/StubFunctionThenTrait.swift @@ -7,7 +7,7 @@ // public protocol StubFunctionThenTrait: BaseStubFunctionTrait { - /// Invoke `implementation` when invoked. + /// Invokes `implementation` when invoked. func then(implementation: IN -> OUT) -> Self }