Skip to content

Commit 7f38d7a

Browse files
authored
Merge pull request #758 from Quick/readme-matcher-deprecation
Update README to align with Matcher deprecation
2 parents ef0d941 + cd85649 commit 7f38d7a

File tree

1 file changed

+15
-18
lines changed

1 file changed

+15
-18
lines changed

README.md

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1512,11 +1512,9 @@ custom matcher. The example below defines the class method
15121512
// Swift
15131513

15141514
extension 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
15591557
expect(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
15791576
extension 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

Comments
 (0)