Search code examples
swiftmatcherochamcrestexpecta

iOS/Mac OS fluent matching framework that works with Swift?


Is there a fluent matching API that works for Swift code? The leading Objective-C matcher candidates seem to be OCHamcrest and Expecta, both of which rely on complex macros that (as per the docs) aren't available to Swift code, e.g.

#define HC_assertThat(actual, matcher)  \
    HC_assertThatWithLocation(self, actual, matcher, __FILE__, __LINE__)

(OCHamcrest)

#define EXP_expect(actual) _EXP_expect(self, __LINE__, __FILE__, ^id{ return EXPObjectify((actual)); })

(Expecta)

Is there another alternative that does work with Swift, or some way to wrap one or the other of these so they can be used with Swift?


ETA: For future readers -- I looked at SwiftHamcrest (per Jon Reid's answer) but for the time being I've settled on Quick/Nimble.


Solution

  • https://github.com/nschum/SwiftHamcrest is a Swift-native implementation of Hamcrest