Skip to content

Commit d01fdfc

Browse files
committed
Expand on cases that are ok
1 parent 752084b commit d01fdfc

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

vignettes/custom-expectation.Rmd

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,15 @@ In this vignette, you'll learn about the three-part structure of expectations, h
2323

2424
## Do you need it?
2525

26-
But before you read the rest of the vignette and dive into the full details of creating a 100% correct expectation, consider if you can get away with a simpler wrapper. For example, take this expectation from tidytext:
26+
But before you read the rest of the vignette and dive into the full details of creating a 100% correct expectation, consider if you can get away with a simpler wrapper. If you're just customising an existing expectation by changing some defaults, you're fine:
27+
28+
```{r}
29+
expect_df <- function(tbl) {
30+
expect_s3_class(tbl, "data.frame")
31+
}
32+
```
33+
34+
If you're combining multiple expectations, you can introduce a subtle problem. For example, take this expectation from tidytext:
2735

2836
```{r}
2937
# from tidytext
@@ -33,7 +41,7 @@ expect_nrow <- function(tbl, n) {
3341
}
3442
```
3543

36-
If we use it in a test you can see there's a subtle problem:
44+
If we use it in a test you can see there's an issue:
3745

3846
```{r}
3947
#| error: true
@@ -48,7 +56,11 @@ test_that("failure 2", {
4856
})
4957
```
5058

51-
Each of these tests contain a single expectation, but they report a total of 2 successes and failures. It would be confusing if testthat didn't report these numbers correctly. But as a helper in your package, it's probably not a big deal and you save yourself some pain by not reading this vignette 😀. You might also notice that these failures generate a backtrace whereas most failures don't. Again this is not a big deal, and the backtrace is correct, it's just not needed.
59+
Each of these tests contain a single expectation, but they report a total of two successes and failures. It would be confusing if testthat didn't report these numbers correctly. But as a helper in your package, it's probably not a big deal.
60+
61+
You might also notice that these failures generate a backtrace whereas built-in expectations don't. Again, it's not a big deal because the backtrace is correct, it's just not needed.
62+
63+
These are both minor issues, so if they don't bother you, you can save yourself some pain by not reading this vignette 😀.
5264

5365
## Expectation basics
5466

0 commit comments

Comments
 (0)