From 51d5438f79ebd8fbfdaab513e9136cdd6521afab Mon Sep 17 00:00:00 2001 From: Rachel Brindle Date: Wed, 11 Dec 2024 16:17:04 -0800 Subject: [PATCH] Allow beIdenticalTo and be to be used as composed matchers (#1178) --- Sources/Nimble/Matchers/BeIdenticalTo.swift | 4 ++-- Tests/NimbleTests/Matchers/BeIdenticalToObjectTest.swift | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Sources/Nimble/Matchers/BeIdenticalTo.swift b/Sources/Nimble/Matchers/BeIdenticalTo.swift index 3f00b187f..85e5b50c8 100644 --- a/Sources/Nimble/Matchers/BeIdenticalTo.swift +++ b/Sources/Nimble/Matchers/BeIdenticalTo.swift @@ -1,6 +1,6 @@ /// A Nimble matcher that succeeds when the actual value is the same instance /// as the expected instance. -public func beIdenticalTo(_ expected: AnyObject?) -> Matcher { +public func beIdenticalTo(_ expected: T?) -> Matcher { return Matcher.define { actualExpression in let actual = try actualExpression.evaluate() @@ -35,7 +35,7 @@ public func !== (lhs: AsyncExpectation, rhs: AnyObject?) async { /// as the expected instance. /// /// Alias for "beIdenticalTo". -public func be(_ expected: AnyObject?) -> Matcher { +public func be(_ expected: T?) -> Matcher { return beIdenticalTo(expected) } diff --git a/Tests/NimbleTests/Matchers/BeIdenticalToObjectTest.swift b/Tests/NimbleTests/Matchers/BeIdenticalToObjectTest.swift index a82077b2e..0ba2316d0 100644 --- a/Tests/NimbleTests/Matchers/BeIdenticalToObjectTest.swift +++ b/Tests/NimbleTests/Matchers/BeIdenticalToObjectTest.swift @@ -12,6 +12,8 @@ final class BeIdenticalToObjectTest: XCTestCase { func testBeIdenticalToPositive() { expect(self.testObjectA).to(beIdenticalTo(testObjectA)) + // check that the typing works out when used as a submatcher. + expect(self.testObjectA).to(map({ $0 }, beIdenticalTo(testObjectA))) } func testBeIdenticalToNegative() {