You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: vignettes/custom-expectation.Rmd
+15-3Lines changed: 15 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -23,7 +23,15 @@ In this vignette, you'll learn about the three-part structure of expectations, h
23
23
24
24
## Do you need it?
25
25
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:
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:
37
45
38
46
```{r}
39
47
#| error: true
@@ -48,7 +56,11 @@ test_that("failure 2", {
48
56
})
49
57
```
50
58
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 😀.
0 commit comments