This is essentially expect, but it returns the result of the expression if the matcher passes (and throws if it doesn't). Very useful for cases where you want to make sure the matcher passes before continuing with a test.
Also, in addition to the require dsl, this also adds unwrap and pollUnwrap, which are shorthands for require(...).toNot(beNil()) and require(...).toEventuallyNot(beNil()).
This also marks Expectation.onFailure as deprecated, as the require DSL entirely replaces that API.
Todo for this PR:
[x] Backfill more tests.
[x] Polling functionality (toEventually and the like).
[x] unwrap but for polling functionality (a shorthand for require(...).toEventuallyNot(beNil()).
[x] Support async expressions and matchers.
[x] require's to/toNot/toEventually/etc. methods should be tagged with @discardableResult.
[x] Documentation.
Future Work
Get better at caching expression such that the last call to an expression is cached. It makes no sense that we evaluate the expression at least twice in both expect and require - in the matcher, and when putting together the error information.
Clean up Expression so that it's () -> Value instead of () -> Value?.
Clean up the polling code so that there's a whole lot less duplication.
In my own dogfooding of this, I realized that it'll be a fairly common usecase to use require simply as a gate, and not to return the value from an expression once it passes a matcher.
Fixes #1102
This is essentially
expect
, but it returns the result of the expression if the matcher passes (and throws if it doesn't). Very useful for cases where you want to make sure the matcher passes before continuing with a test.Also, in addition to the require dsl, this also adds
unwrap
andpollUnwrap
, which are shorthands forrequire(...).toNot(beNil())
andrequire(...).toEventuallyNot(beNil())
.This also marks
Expectation.onFailure
as deprecated, as the require DSL entirely replaces that API.Todo for this PR:
toEventually
and the like).unwrap
but for polling functionality (a shorthand forrequire(...).toEventuallyNot(beNil())
.@discardableResult
.Future Work
expression
such that the last call to an expression is cached. It makes no sense that we evaluate the expression at least twice in bothexpect
andrequire
- in the matcher, and when putting together the error information.() -> Value
instead of() -> Value?
.