2018-12-27 22:24:20 +00:00
|
|
|
//
|
2024-02-05 21:03:51 +00:00
|
|
|
// ResultPredicates.swift
|
2018-12-27 22:24:20 +00:00
|
|
|
// MasKitTests
|
|
|
|
//
|
|
|
|
// Created by Ben Chatelain on 12/27/18.
|
|
|
|
// Copyright © 2018 mas-cli. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import Nimble
|
|
|
|
|
2021-03-22 05:25:18 +00:00
|
|
|
@testable import MasKit
|
|
|
|
|
2018-12-27 22:24:20 +00:00
|
|
|
/// Nimble predicate for result enum success case, no associated value
|
2021-03-22 05:46:17 +00:00
|
|
|
func beSuccess() -> Predicate<Result<Void, MASError>> {
|
|
|
|
Predicate.define("be <success>") { expression, message in
|
2021-03-22 05:25:18 +00:00
|
|
|
if case .success = try expression.evaluate() {
|
2018-12-27 22:24:20 +00:00
|
|
|
return PredicateResult(status: .matches, message: message)
|
|
|
|
}
|
|
|
|
return PredicateResult(status: .fail, message: message)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Nimble predicate for result enum failure with associated error
|
2021-03-22 05:46:17 +00:00
|
|
|
func beFailure(test: @escaping (MASError) -> Void = { _ in }) -> Predicate<Result<Void, MASError>> {
|
|
|
|
Predicate.define("be <failure>") { expression, message in
|
2021-05-08 20:26:25 +00:00
|
|
|
if case .failure(let error) = try expression.evaluate() {
|
2018-12-27 22:24:20 +00:00
|
|
|
test(error)
|
|
|
|
return PredicateResult(status: .matches, message: message)
|
|
|
|
}
|
|
|
|
return PredicateResult(status: .fail, message: message)
|
|
|
|
}
|
|
|
|
}
|