forked from Kolos65/Mockable
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: extend relaxed mode to custom types
- Loading branch information
Showing
37 changed files
with
317 additions
and
354 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
This file was deleted.
Oops, something went wrong.
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
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
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
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
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
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
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
6 changes: 3 additions & 3 deletions
6
Sources/Mockable/Mockable.swift → Sources/Mockable/Builder/MockService.swift
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
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
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
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
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
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
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,66 @@ | ||
// | ||
// Mockable.swift | ||
// Mockable | ||
// | ||
// Created by Kolos Foltanyi on 2024. 04. 03.. | ||
// | ||
|
||
/// A protocol that represents auto-mocked types. | ||
/// | ||
/// `Mockable` in combination with a `relaxedMockable` option of `MockerPolicy `can be used | ||
/// to set an implicit return value for custom types: | ||
/// | ||
/// ```swift | ||
/// struct Car { | ||
/// var name: String | ||
/// var seats: Int | ||
/// } | ||
/// | ||
/// extension Car: Mockable { | ||
/// static var mock: Car { | ||
/// Car(name: "Mock Car", seats: 4) | ||
/// } | ||
/// | ||
/// // Defaults to [mock] but we can | ||
/// // provide a custom array of cars: | ||
/// static var mocks: [Car] { | ||
/// [ | ||
/// Car(name: "Mock Car 1", seats: 4), | ||
/// Car(name: "Mock Car 2", seats: 4) | ||
/// ] | ||
/// } | ||
/// } | ||
/// | ||
/// @Mockable | ||
/// protocol CarService { | ||
/// func getCar() -> Car | ||
/// func getCars() -> [Car] | ||
/// } | ||
/// | ||
/// func testCarService() { | ||
/// func test() { | ||
/// let mock = MockCarService(policy: .relaxedMockable) | ||
/// // Implictly mocked without a given registration: | ||
/// let car = mock.getCar() | ||
/// let cars = mock.getCars() | ||
/// } | ||
/// } | ||
/// ``` | ||
public protocol Mockable { | ||
/// A default mock return value to use when `.relaxedMocked` policy is set. | ||
static var mock: Self { get } | ||
|
||
/// An array of mock values to use as return values when `.relaxedMocked` policy is set. | ||
/// Defaults to `[Self.mock]`. | ||
static var mocks: [Self] { get } | ||
} | ||
|
||
extension Mockable { | ||
public static var mocks: [Self] { [mock] } | ||
} | ||
|
||
extension Array: Mockable where Element: Mockable { | ||
public static var mock: Self { | ||
Element.mocks | ||
} | ||
} |
Oops, something went wrong.