Nimble icon indicating copy to clipboard operation
Nimble copied to clipboard

Expectations of kind "beAKindOf" and "beAnInstanceOf" not working

Open rmato opened this issue 8 years ago • 4 comments

  • [x] I have read CONTRIBUTING and have done my best to follow them.

What did you do?

    expect(configurationHandler).to(beAKindOf(AVISensorConfiguration.self))
    expect(configurationHandler).to(beAnInstanceOf(AVISensorConfiguration.self))

What did you expect to happen?

configurationHandler is an actual instance of AVISensorConfiguration. So I expected the test to pass.

What actually happened instead?

Test Failed with descriptions:

  • "expected to be a kind of AVISensorConfiguration, got <AVISensorConfiguration instance>"
  • "expected to be an instance of AVISensorConfiguration, got <AVISensorConfiguration instance> " Both fail

Environment

List the software versions you're using:

  • Quick: ?.?.?
  • Nimble: 7.0.3
  • Xcode Version: 9.2 (9C40b)
  • Swift Version: Xcode Default

Please also mention which package manager you used and its version. Delete the other package managers in this list:

  • Cocoapods: 1.3.1

Project that demonstrates the issue

Please link to a project we can download that reproduces the issue. Feel free to delete this section if it's not relevant to the issue (eg - feature request).

The project should be short, self-contained, and correct example.

rmato avatar Dec 15 '17 23:12 rmato

Hi @rmato -

I've taken a crack at reproducing the issue that you've experienced. Here's the modification that I made to the tests for beAnInstanceOf:

private class Superclass {}
private class Subclass: Superclass {}
private class SubclassOfSubclass: Subclass {}

...
        let superclass = Superclass()
        expect(superclass).to(beAnInstanceOf(Superclass.self))
        expect(superclass).toNot(beAnInstanceOf(Subclass.self))
        expect(superclass).toNot(beAnInstanceOf(SubclassOfSubclass.self))
        
        let subclass = Subclass()
        expect(subclass).toNot(beAnInstanceOf(Superclass.self))
        expect(subclass).to(beAnInstanceOf(Subclass.self))
        expect(subclass).toNot(beAnInstanceOf(SubclassOfSubclass.self))
        
        let subclassOfSubclass = SubclassOfSubclass()
        expect(subclassOfSubclass).toNot(beAnInstanceOf(Superclass.self))
        expect(subclassOfSubclass).toNot(beAnInstanceOf(Subclass.self))
        expect(subclassOfSubclass).to(beAnInstanceOf(SubclassOfSubclass.self))

The tests above all passed as you'd expect them to. Do you have any example code we could work off of to try to figure out what's going on?

jwfriese avatar Dec 23 '17 02:12 jwfriese

Closing this due to inactivity.

ikesyo avatar Apr 11 '18 19:04 ikesyo

I'm seeing this issue as well. If it helps, the types are structs that are included via a Cocoapod that is linked statically. All of the structs that are failing extend a protocol. The expect portion of the expression is an optional array of the protocol and I'm comparing an instance of an index in the array.

// Definitions
public protocol MyProtocol {}
public struct MyStruct: MyProtocol {}

// Test
// object.myElements is Optional<Array<MyProtocol>>
expect(object.myElements?[0]).to(beAnInstanceOf(MyStruct.self))

Within beAnInstanceOf I have added the following statements

print("ExpectedType: \(expectedType)")
print("ValidInstance: \(type(of: validInstance))")
print("ExpectedType: \(String(describing: expectedType))")
print("ValidInstance: \(String(describing: type(of: validInstance)))")
print("Matches: \(type(of: validInstance) == expectedType)")

which prints

ExpectedType: MyStruct
ValidInstance: MyStruct
ExpectedType: MyStruct
ValidInstance: MyStruct
Matches: false

I have validated MyStruct does not exist in any other project, so it's not just two types with the same name.

bclymer avatar Dec 05 '18 03:12 bclymer

Update that I realized immediately after typing that comment. I'm seeing

objc[45000]: Class <blah> is implemented in both <bleh> and <bluh>

That's almost for sure the issue. The left side (expect) is the impl included with the app itself, and the right side (beAnInstanceOf) is the impl included with the test bundle.

bclymer avatar Dec 05 '18 03:12 bclymer