Skip to content

Instantly share code, notes, and snippets.

@rkawajiri
Created March 1, 2016 06:28
Show Gist options
  • Save rkawajiri/90076b106589980adaec to your computer and use it in GitHub Desktop.
Save rkawajiri/90076b106589980adaec to your computer and use it in GitHub Desktop.
Util Nimble Matcher
import Nimble
func notBeNilAnd<T>(closure: (actual: T) -> Void) -> MatcherFunc<T> {
return MatcherFunc { actualExpression, failureMessage in
failureMessage.postfixMessage = "be nil"
guard let actual = try actualExpression.evaluate() else {
return false
}
closure(actual: actual)
return true
}
}
it("hoge[\"foo\"].bar should be 'bar'") {
expect(hoge["foo"]).to(notBeNilAnd { (foo: Foo) in // <- Specify type to pass build
expect(foo.bar).to(notBeNilAnd { (bar: Bar) in
expect(bar).to(equal("bar"))
})
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment