Skip to content

Commit

Permalink
refactor: rewrite Fakeable
Browse files Browse the repository at this point in the history
  • Loading branch information
0xWOF committed Nov 13, 2023
1 parent f017c79 commit a99ccf7
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
12 changes: 12 additions & 0 deletions Source/TestFake/FakeDependency.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//
// FakeDependency.swift
// SabyTestFake
//
// Created by WOF on 11/13/23.
//

import Foundation

public protocol FakeDependency {
init()
}
17 changes: 15 additions & 2 deletions Source/TestFake/Fakeable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,19 @@

import Foundation

public protocol Fakeable {
static func fake() -> Self
public protocol Fakeable<Dependency> {
associatedtype Dependency: FakeDependency

init(dependency: Dependency)
}

extension Fakeable {
static func fake(apply: (inout Dependency) -> Void) -> (Self, Dependency) {
var dependency = Dependency()
apply(&dependency)

let instance = Self(dependency: dependency)

return (instance, dependency)
}
}

0 comments on commit a99ccf7

Please sign in to comment.