5
// A Nimble matcher that catches attempts to use beAKindOf with non Objective-C types
6
public func beAKindOf(expectedClass: Any) -> NonNilMatcherFunc<Any> {
7
return NonNilMatcherFunc {actualExpression, failureMessage in
8
failureMessage.stringValue = "beAKindOf only works on Objective-C types since"
9
+ " the Swift compiler will automatically type check Swift-only types."
10
+ " This expectation is redundant."
15
/// A Nimble matcher that succeeds when the actual value is an instance of the given class.
16
/// @see beAnInstanceOf if you want to match against the exact class
17
public func beAKindOf(expectedClass: AnyClass) -> NonNilMatcherFunc<NSObject> {
18
return NonNilMatcherFunc { actualExpression, failureMessage in
19
let instance = try actualExpression.evaluate()
20
if let validInstance = instance {
21
failureMessage.actualValue = "<\(classAsString(validInstance.dynamicType)) instance>"
23
failureMessage.actualValue = "<nil>"
25
failureMessage.postfixMessage = "be a kind of \(classAsString(expectedClass))"
26
return instance != nil && instance!.isKindOfClass(expectedClass)
30
extension NMBObjCMatcher {
31
public class func beAKindOfMatcher(expected: AnyClass) -> NMBMatcher {
32
return NMBObjCMatcher(canMatchNil: false) { actualExpression, failureMessage in
33
return try! beAKindOf(expected).matches(actualExpression, failureMessage: failureMessage)