Skip to content

Commit 856b940

Browse files
authored
Allow beAKindOf and beAnInstanceOf to nest inside of other matchers (#1173)
1 parent 47ba9ec commit 856b940

File tree

4 files changed

+14
-2
lines changed

4 files changed

+14
-2
lines changed

Sources/Nimble/Matchers/BeAKindOf.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ private func matcherMessage(forClass expectedClass: AnyClass) -> String {
66
}
77

88
/// A Nimble matcher that succeeds when the actual value is an instance of the given class.
9-
public func beAKindOf<T>(_ expectedType: T.Type) -> Matcher<Any> {
9+
public func beAKindOf<T, U>(_ expectedType: T.Type) -> Matcher<U> {
1010
return Matcher.define { actualExpression in
1111
let message: ExpectationMessage
1212

Sources/Nimble/Matchers/BeAnInstanceOf.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import Foundation
22

33
/// A Nimble matcher that succeeds when the actual value is an _exact_ instance of the given class.
4-
public func beAnInstanceOf<T>(_ expectedType: T.Type) -> Matcher<Any> {
4+
public func beAnInstanceOf<T, U>(_ expectedType: T.Type) -> Matcher<U> {
55
let errorMessage = "be an instance of \(String(describing: expectedType))"
66
return Matcher.define { actualExpression in
77
let instance = try actualExpression.evaluate()

Tests/NimbleTests/Matchers/BeAKindOfTest.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ final class BeAKindOfSwiftTest: XCTestCase {
3434
expect(testProtocolStruct).toNot(beAKindOf(TestClassConformingToProtocol.self))
3535
}
3636

37+
func testNestedMatchers() {
38+
// This test is successful if it even compiles.
39+
let result: Result<Int, Error> = .success(1)
40+
expect(result).to(beSuccess(beAKindOf(Int.self)))
41+
}
42+
3743
func testFailureMessages() {
3844
failsWithErrorMessage("expected to not be a kind of Int, got <Int instance>") {
3945
expect(1).toNot(beAKindOf(Int.self))

Tests/NimbleTests/Matchers/BeAnInstanceOfTest.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ final class BeAnInstanceOfTest: XCTestCase {
3636
expect(testProtocolStruct).toNot(beAnInstanceOf(TestClassConformingToProtocol.self))
3737
}
3838

39+
func testNestedMatchers() {
40+
// This test is successful if it even compiles.
41+
let result: Result<Int, Error> = .success(1)
42+
expect(result).to(beSuccess(beAnInstanceOf(Int.self)))
43+
}
44+
3945
func testFailureMessages() {
4046
failsWithErrorMessageForNil("expected to not be an instance of NSNull, got <nil>") {
4147
expect(nil as NSNull?).toNot(beAnInstanceOf(NSNull.self))

0 commit comments

Comments
 (0)