mas/Tests/MasKitTests/Nimble/ResultPredicates.swift

33 lines
1 KiB
Swift
Raw Normal View History

//
// ResultPredicates.swift
// 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
/// 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() {
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
if case .failure(let error) = try expression.evaluate() {
test(error)
return PredicateResult(status: .matches, message: message)
}
return PredicateResult(status: .fail, message: message)
}
}