@@ -8,33 +8,39 @@ import Foundation
88/// A Nimble matcher that succeeds when the actual Collection's count equals
99/// the expected value
1010public func haveCount< T: Collection > ( _ expectedValue: T . IndexDistance ) -> Predicate < T > {
11- return Predicate . fromDeprecatedClosure { actualExpression, failureMessage in
11+ return Predicate . define { actualExpression in
1212 if let actualValue = try actualExpression. evaluate ( ) {
13- // swiftlint:disable:next line_length
14- failureMessage. postfixMessage = " have \( prettyCollectionType ( actualValue) ) with count \( stringify ( expectedValue) ) "
13+ let message = ExpectationMessage
14+ . expectedCustomValueTo (
15+ " have \( prettyCollectionType ( actualValue) ) with count \( stringify ( expectedValue) ) " ,
16+ " \( actualValue. count) "
17+ )
18+ . appended ( details: " Actual Value: \( stringify ( actualValue) ) " )
19+
1520 let result = expectedValue == actualValue. count
16- failureMessage. actualValue = " \( actualValue. count) "
17- failureMessage. extendedMessage = " Actual Value: \( stringify ( actualValue) ) "
18- return result
21+ return PredicateResult ( bool: result, message: message)
1922 } else {
20- return false
23+ return PredicateResult ( status : . fail , message : . fail ( " " ) )
2124 }
22- } . requireNonNil
25+ }
2326}
2427
2528/// A Nimble matcher that succeeds when the actual collection's count equals
2629/// the expected value
2730public func haveCount( _ expectedValue: Int ) -> Predicate < NMBCollection > {
28- return Predicate . fromDeprecatedClosure { actualExpression, failureMessage in
31+ return Predicate { actualExpression in
2932 if let actualValue = try actualExpression. evaluate ( ) {
30- // swiftlint:disable:next line_length
31- failureMessage. postfixMessage = " have \( prettyCollectionType ( actualValue) ) with count \( stringify ( expectedValue) ) "
33+ let message = ExpectationMessage
34+ . expectedCustomValueTo (
35+ " have \( prettyCollectionType ( actualValue) ) with count \( stringify ( expectedValue) ) " ,
36+ " \( actualValue. count) "
37+ )
38+ . appended ( details: " Actual Value: \( stringify ( actualValue) ) " )
39+
3240 let result = expectedValue == actualValue. count
33- failureMessage. actualValue = " \( actualValue. count) "
34- failureMessage. extendedMessage = " Actual Value: \( stringify ( actualValue) ) "
35- return result
41+ return PredicateResult ( bool: result, message: message)
3642 } else {
37- return false
43+ return PredicateResult ( status : . fail , message : . fail ( " " ) )
3844 }
3945 }
4046}
0 commit comments