-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Proposal] - Define Mocks and stubs next to the implementation (#172)
* Mocks and stubs to the source * Update Cookbook/Proposals/MocksAndStubsNextToImplementation.md Co-Authored-By: João Pereira <[email protected]> * Update Cookbook/Proposals/MocksAndStubsNextToImplementation.md Co-Authored-By: João Pereira <[email protected]> Co-authored-by: João Pereira <[email protected]>
- Loading branch information
Showing
1 changed file
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Never, BiometricAuthError> | ||
func unregister() -> SignalProducer<Never, BiometricAuthError> | ||
func signedNonce() -> SignalProducer<Data, BiometricAuthError> | ||
} | ||
|
||
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 | ||
|