Quick / Nimble

A Matcher Framework for Swift and Objective-C
https://quick.github.io/Nimble/documentation/nimble/
Apache License 2.0
4.79k stars 595 forks source link

Introduce the require dsl. For when you need the assertion to pass before continuing #1103

Closed younata closed 6 months ago

younata commented 7 months ago

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 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:

Future Work

younata commented 7 months ago

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.