kylef / Spectre

BDD Framework and test runner for Swift projects and playgrounds
BSD 2-Clause "Simplified" License
404 stars 41 forks source link

Adding support for type comparison #22

Closed stupergenius closed 7 years ago

stupergenius commented 7 years ago

As described in #14, adding a method so we can now do something like:

try expect("kyle").to.beOfType(String.self)

Also updated the docs.

I did also attempt to support doing something like:

try expect(Mirror(reflecting: "kyle").subjectType)) == String.self

But I kept bumping up against the fact that Any.Type is a "metatype", which I don't really understand, but it means you can't, for instance, write a version of the equality operator like:

public func == <E: ExpectationType>(lhs: E, rhs: E.ValueType) throws where E.ValueType: Any.Type { ... }

Nor does something like the below work because Any is not Equatable:

public func == <E: ExpectationType>(lhs: E, rhs: E.ValueType) throws where E.ValueType: Any { ... }

Perhaps I'm coming at this the wrong way, but at least the to.beOfType use case is now supported!