Skip to content

Commit

Permalink
[Proposal] - Define Mocks and stubs next to the implementation (#172)
Browse files Browse the repository at this point in the history
* 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
sergdort and NSMyself authored Sep 28, 2020
1 parent e171a44 commit f1fed5b
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions Cookbook/Proposals/MocksAndStubsNextToImplementation.md
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

0 comments on commit f1fed5b

Please sign in to comment.