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: move given and when helpers to main target
- Loading branch information
Showing
2 changed files
with
54 additions
and
48 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,54 @@ | ||
// | ||
// Utils.swift | ||
// Mockable | ||
// | ||
// Created by Kolos Foltanyi on 2024. 03. 17.. | ||
// | ||
|
||
/// Creates a proxy for building return values for members of the given service. | ||
/// | ||
/// Example usage of `given(_ service:)`: | ||
/// ```swift | ||
/// // Throw an error for the first call and then return 'product' for every other call | ||
/// given(productService) | ||
/// .fetch(for: .any).willThrow(error) | ||
/// .fetch(for: .any).willReturn(product) | ||
/// | ||
/// // Throw an error if the id parameter ends with a 0, return a product otherwise | ||
/// given(productService) | ||
/// .fetch(for: .any).willProduce { id in | ||
/// if id.uuidString.last == "0" { | ||
/// throw error | ||
/// } else { | ||
/// return product | ||
/// } | ||
/// } | ||
/// ``` | ||
/// | ||
/// - Parameter service: The mockable service for which return values are specified. | ||
/// - Returns: The service's return value builder. | ||
public func given<T: Mockable>(_ service: T) -> T.ReturnBuilder { service.given() } | ||
|
||
/// Creates a proxy for building actions for members of the given service. | ||
/// | ||
/// Example usage of `when(_ service:)`: | ||
/// ```swift | ||
/// // log calls to fetch(for:) | ||
/// when(productService).fetch(for: .any).perform { | ||
/// print("fetch(for:) was called") | ||
/// } | ||
/// | ||
/// // log when url is accessed | ||
/// when(productService).url().performOnGet { | ||
/// print("url accessed") | ||
/// } | ||
/// | ||
/// // log when url is set to nil | ||
/// when(productService).url(newValue: .value(nil)).performOnSet { | ||
/// print("url set to nil") | ||
/// } | ||
/// ``` | ||
/// | ||
/// - Parameter service: The mockable service for which actions are specified. | ||
/// - Returns: The service's action builder. | ||
public func when<T: Mockable>(_ service: T) -> T.ActionBuilder { service.when() } |
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