@@ -1512,11 +1512,9 @@ custom matcher. The example below defines the class method
15121512// Swift
15131513
15141514extension NMBObjCMatcher {
1515- public class func beNilMatcher () -> NMBObjCMatcher {
1516- return NMBObjCMatcher { actualBlock, failureMessage, location in
1517- let block = ({ actualBlock () as NSObject? })
1518- let expr = Expression (expression : block, location : location)
1519- return beNil ().matches (expr, failureMessage : failureMessage)
1515+ @objc public class func beNilMatcher () -> NMBPredicate {
1516+ return NMBPredicate { actualExpression in
1517+ return try beNil ().satisfies (actualExpression).toObjectiveC ()
15201518 }
15211519 }
15221520}
@@ -1559,29 +1557,28 @@ expect(nil).to(equal(nil)); // fails
15591557expect(nil).to(beNil()); // passes
15601558```
15611559
1562- If your matcher does not want to match with nil, you use `NonNilMatcherFunc`
1563- and the `canMatchNil` constructor on `NMBObjCMatcher`. Using both types will
1564- automatically generate expected value failure messages when they're nil.
1560+ If your matcher does not want to match with nil, you use `Predicate.define` or `Predicate.simple`.
1561+ Using those factory methods will automatically generate expected value failure messages when they're nil.
15651562
15661563```swift
15671564
1568- public func beginWith<S: Sequence, T: Equatable where S.Iterator.Element == T>( startingElement: T) -> NonNilMatcherFunc <S> {
1569- return NonNilMatcherFunc { actualExpression, failureMessage in
1570- failureMessage.postfixMessage = "begin with <\(startingElement)>"
1571- if let actualValue = actualExpression.evaluate() {
1565+ public func beginWith<S: Sequence, T: Equatable>(_ startingElement: T) -> Predicate <S>
1566+ where S.Iterator.Element == T {
1567+ return Predicate.simple( "begin with <\(startingElement)>") { actualExpression in
1568+ if let actualValue = try actualExpression.evaluate() {
15721569 var actualGenerator = actualValue.makeIterator()
1573- return actualGenerator.next() == startingElement
1570+ return PredicateStatus(bool: actualGenerator.next() == startingElement)
15741571 }
1575- return false
1572+ return .fail
15761573 }
15771574}
15781575
15791576extension NMBObjCMatcher {
1580- public class func beginWithMatcher(expected: AnyObject ) -> NMBObjCMatcher {
1581- return NMBObjCMatcher(canMatchNil: false) { actualExpression, failureMessage in
1582- let actual = actualExpression.evaluate()
1577+ @objc public class func beginWithMatcher(_ expected: Any ) -> NMBPredicate {
1578+ return NMBPredicate { actualExpression in
1579+ let actual = try actualExpression.evaluate()
15831580 let expr = actualExpression.cast { $0 as? NMBOrderedCollection }
1584- return beginWith(expected).matches (expr, failureMessage: failureMessage )
1581+ return try beginWith(expected).satisfies (expr).toObjectiveC( )
15851582 }
15861583 }
15871584}
0 commit comments