From f1fed5b59e56718251b10a62320c61d333639cb8 Mon Sep 17 00:00:00 2001 From: sergdort Date: Mon, 28 Sep 2020 09:09:38 +0100 Subject: [PATCH] [Proposal] - Define Mocks and stubs next to the implementation (#172) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Mocks and stubs to the source * Update Cookbook/Proposals/MocksAndStubsNextToImplementation.md Co-Authored-By: João Pereira * Update Cookbook/Proposals/MocksAndStubsNextToImplementation.md Co-Authored-By: João Pereira Co-authored-by: João Pereira --- .../MocksAndStubsNextToImplementation.md | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 Cookbook/Proposals/MocksAndStubsNextToImplementation.md diff --git a/Cookbook/Proposals/MocksAndStubsNextToImplementation.md b/Cookbook/Proposals/MocksAndStubsNextToImplementation.md new file mode 100644 index 000000000..653673863 --- /dev/null +++ b/Cookbook/Proposals/MocksAndStubsNextToImplementation.md @@ -0,0 +1,53 @@ +# Put Mocks, Stubs Next to Implementation + +* Author(s): Sergey Shulga +* Review Manager: TBD + +## Introduction + +Put implementation of mocks next to the implementation of the protocol + +## Motivation + + +- Improves Discoverability of mocks +- Prevents mocks duplication (Because we usually define mocks in the `FrameworkTests` target which means they can only be used there) +- Easy to change mock implementation once public API changes + + +## Proposed solution + + +```swift +public protocol BiometricAuthControllerProtocol { + var isRegistered: Bool { get } + var supportedBiometry: BiometryType { get } + var biometricDataHasChanged: Bool { get } + + func register() -> SignalProducer + func unregister() -> SignalProducer + func signedNonce() -> SignalProducer +} + +public final class BiometricAuthController: BiometricAuthControllerProtocol { +// Implementation +} + +#if DEBUG + +public final class MockBiometricAuthController: BiometricAuthControllerProtocol { +// Implementation +} + +#endif + +``` + +## Impact on existing codebase + +This proposal does not break anything, allows gradual migration. + +## Alternatives considered + +Leave as it is +