From a99ccf7185ed0bbf0b0ca8f5920533c7381e0459 Mon Sep 17 00:00:00 2001 From: Subeom Choi Date: Mon, 13 Nov 2023 11:54:35 +0900 Subject: [PATCH] refactor: rewrite Fakeable --- Source/TestFake/FakeDependency.swift | 12 ++++++++++++ Source/TestFake/Fakeable.swift | 17 +++++++++++++++-- 2 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 Source/TestFake/FakeDependency.swift diff --git a/Source/TestFake/FakeDependency.swift b/Source/TestFake/FakeDependency.swift new file mode 100644 index 0000000..2f282ca --- /dev/null +++ b/Source/TestFake/FakeDependency.swift @@ -0,0 +1,12 @@ +// +// FakeDependency.swift +// SabyTestFake +// +// Created by WOF on 11/13/23. +// + +import Foundation + +public protocol FakeDependency { + init() +} diff --git a/Source/TestFake/Fakeable.swift b/Source/TestFake/Fakeable.swift index 7079d26..9a240a7 100644 --- a/Source/TestFake/Fakeable.swift +++ b/Source/TestFake/Fakeable.swift @@ -7,6 +7,19 @@ import Foundation -public protocol Fakeable { - static func fake() -> Self +public protocol Fakeable { + 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) + } }