Skip to content

Commit 6639400

Browse files
committed
Fix regression where be and beIdenticalTo matchers stopped matching against AnyObject protocols
1 parent 6de3456 commit 6639400

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

Sources/Nimble/Matchers/BeIdenticalTo.swift

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
/// A Nimble matcher that succeeds when the actual value is the same instance
22
/// as the expected instance.
33
public func beIdenticalTo<T: AnyObject>(_ expected: T?) -> Matcher<T> {
4+
_beIdenticalTo(expected)
5+
}
6+
7+
/// A Nimble matcher that succeeds when the actual value is the same instance
8+
/// as the expected instance.
9+
public func beIdenticalTo(_ expected: AnyObject?) -> Matcher<AnyObject> {
10+
_beIdenticalTo(expected)
11+
}
12+
13+
private func _beIdenticalTo<T: AnyObject>(_ expected: T?) -> Matcher<T> {
414
return Matcher.define { actualExpression in
515
let actual = try actualExpression.evaluate()
616

@@ -36,7 +46,15 @@ public func !== (lhs: AsyncExpectation<AnyObject>, rhs: AnyObject?) async {
3646
///
3747
/// Alias for "beIdenticalTo".
3848
public func be<T: AnyObject>(_ expected: T?) -> Matcher<T> {
39-
return beIdenticalTo(expected)
49+
return _beIdenticalTo(expected)
50+
}
51+
52+
/// A Nimble matcher that succeeds when the actual value is the same instance
53+
/// as the expected instance.
54+
///
55+
/// Alias for "beIdenticalTo".
56+
public func be(_ expected: AnyObject?) -> Matcher<AnyObject> {
57+
return _beIdenticalTo(expected)
4058
}
4159

4260
#if canImport(Darwin)

Tests/NimbleTests/Matchers/BeIdenticalToObjectTest.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,26 @@ final class BeIdenticalToObjectTest: XCTestCase {
1212

1313
func testBeIdenticalToPositive() {
1414
expect(self.testObjectA).to(beIdenticalTo(testObjectA))
15+
}
16+
17+
func testbeIdenticalToAsSubmatcher() {
1518
// check that the typing works out when used as a submatcher.
19+
expect(self.testObjectA).to(map({ $0 }, be(testObjectA)))
1620
expect(self.testObjectA).to(map({ $0 }, beIdenticalTo(testObjectA)))
1721
}
1822

23+
func testBeIdenticalToAnyObjectProtocol() {
24+
protocol SomeObject: AnyObject {}
25+
class ConcreteImpl: SomeObject {
26+
init() {}
27+
}
28+
29+
let object = ConcreteImpl()
30+
31+
expect(object as SomeObject).to(be(object))
32+
expect(object as SomeObject).to(beIdenticalTo(object))
33+
}
34+
1935
func testBeIdenticalToNegative() {
2036
expect(self.testObjectA).toNot(beIdenticalTo(testObjectB))
2137
}

0 commit comments

Comments
 (0)