Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow beAKindOf and beAnInstanceOf to nest inside of other matchers #1173

Merged
merged 1 commit into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Sources/Nimble/Matchers/BeAKindOf.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ private func matcherMessage(forClass expectedClass: AnyClass) -> String {
}

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

Expand Down
2 changes: 1 addition & 1 deletion Sources/Nimble/Matchers/BeAnInstanceOf.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Foundation

/// A Nimble matcher that succeeds when the actual value is an _exact_ instance of the given class.
public func beAnInstanceOf<T>(_ expectedType: T.Type) -> Matcher<Any> {
public func beAnInstanceOf<T, U>(_ expectedType: T.Type) -> Matcher<U> {
let errorMessage = "be an instance of \(String(describing: expectedType))"
return Matcher.define { actualExpression in
let instance = try actualExpression.evaluate()
Expand Down
6 changes: 6 additions & 0 deletions Tests/NimbleTests/Matchers/BeAKindOfTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ final class BeAKindOfSwiftTest: XCTestCase {
expect(testProtocolStruct).toNot(beAKindOf(TestClassConformingToProtocol.self))
}

func testNestedMatchers() {
// This test is successful if it even compiles.
let result: Result<Int, Error> = .success(1)
expect(result).to(beSuccess(beAKindOf(Int.self)))
}

func testFailureMessages() {
failsWithErrorMessage("expected to not be a kind of Int, got <Int instance>") {
expect(1).toNot(beAKindOf(Int.self))
Expand Down
6 changes: 6 additions & 0 deletions Tests/NimbleTests/Matchers/BeAnInstanceOfTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ final class BeAnInstanceOfTest: XCTestCase {
expect(testProtocolStruct).toNot(beAnInstanceOf(TestClassConformingToProtocol.self))
}

func testNestedMatchers() {
// This test is successful if it even compiles.
let result: Result<Int, Error> = .success(1)
expect(result).to(beSuccess(beAnInstanceOf(Int.self)))
}

func testFailureMessages() {
failsWithErrorMessageForNil("expected to not be an instance of NSNull, got <nil>") {
expect(nil as NSNull?).toNot(beAnInstanceOf(NSNull.self))
Expand Down
Loading