Skip to content

Commit

Permalink
Allow passing a custom error to be thrown by require
Browse files Browse the repository at this point in the history
  • Loading branch information
younata committed Dec 19, 2023
1 parent e7f6804 commit 3c0df24
Show file tree
Hide file tree
Showing 4 changed files with 199 additions and 57 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -767,6 +767,17 @@ Note: As with `require`, there are `unwraps`, `unwrapa`, `pollUnwraps`, and
`pollUnwrapa` variants for allowing you to use autoclosures specifically with
synchronous or asynchronous code.

## Throwing a Custom Error from Require

By default, if the matcher fails in a `require`, then a `RequireError` will be
thrown. You can override this behavior and throw a custom error by passing a
non-nil `Error` value to the `customError` parameter:

```swift
try require(1).to(equal(2)) // throws a `RequireError`
try require(customError: MyCustomError(), 1).to(equal(2)) // throws a `MyCustomError`
```

# Built-in Matcher Functions

Nimble includes a wide variety of matcher functions.
Expand Down
Loading

0 comments on commit 3c0df24

Please sign in to comment.