Skip to content

Commit aa402f5

Browse files
committed
✨ More proofreading ✨
1 parent 39ddd7c commit aa402f5

File tree

5 files changed

+8
-8
lines changed

5 files changed

+8
-8
lines changed

vignettes/challenging-tests.Rmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ snapper$start_file("snapshotting.Rmd", "test")
2020
Sys.setenv(TESTTHAT_PKG = "testthat")
2121
```
2222

23-
This vignette is a quick reference guide for testing challenging functions. It's organised by the problem, rather the than technique used to solve it, so you can quickly skim the whole vignette, spot the problem you're facing, then learn more about useful tools for solving it.
23+
This vignette is a quick reference guide for testing challenging functions. It's organised by the problem, rather than the technique used to solve it, so you can quickly skim the whole vignette, spot the problem you're facing, then learn more about useful tools for solving it.
2424

2525
## Options and environment variables
2626

vignettes/custom-expectation.Rmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ expect_length <- function(object, n) {
3333
if (act_n != n) {
3434
msg <- c(
3535
sprintf("Expected %s to have length %i.", act$lab, n),
36-
sprintf("Actual length: %i.", act$n)
36+
sprintf("Actual length: %i.", act_n)
3737
)
3838
return(fail(msg))
3939
}

vignettes/mocking.Rmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ Here we pretend that there are no reverse dependencies (revdeps) for the package
158158

159159
### Managing time
160160

161-
but this either made my tests both slow (because I'd sleep for a second or two) and unreliable (because sometimes more time elapsed than I expected). Eventually I figured out that I could "manually control" time by using a [mocked function](https://github.com/r-lib/httr2/blob/main/tests/testthat/test-req-throttle.R) that returns the value of a variable I control. This allows me to manually advance time and carefully test the implications.
161+
`httr2::req_throttle()` prevents multiple requests from being made too quickly, using a tool called a leaky token bucket. This tool is inextricably tied to real time because you want to allow more requests as time elapses. So how do you test this? I started by using `Sys.sleep()` but this either made my tests both slow (because I'd sleep for a second or two) and unreliable (because sometimes more time elapsed than I expected). Eventually I figured out that I could "manually control" time by using a [mocked function](https://github.com/r-lib/httr2/blob/main/tests/testthat/test-req-throttle.R) that returns the value of a variable I control. This allows me to manually advance time and carefully test the implications.
162162

163163
You can see the basic idea with a simpler example. Let's first begin with a function that returns the "unix time", the number of seconds elapsed since midnight on Jan 1 1970. This is easy to compute, but will make some computations simpler later as well as providing a convenient function to mock.
164164

vignettes/skipping.Rmd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ skip_if_dangerous <- function() {
7777
## Embedding `skip()` in package functions
7878

7979
Another potentially useful technique is to build a `skip()` directly into a package function.
80-
For example take a look at [`pkgdown:::convert_markdown_to_html()`](https://github.com/r-lib/pkgdown/blob/v2.0.7/R/markdown.R#L95-L106), which absolutely, positively cannot work if the Pandoc tool is unavailable:
80+
For example, take a look at [`pkgdown:::convert_markdown_to_html()`](https://github.com/r-lib/pkgdown/blob/v2.0.7/R/markdown.R#L95-L106), which absolutely, positively cannot work if the Pandoc tool is unavailable:
8181

8282
```{r eval = FALSE}
8383
convert_markdown_to_html <- function(in_path, out_path, ...) {
@@ -108,7 +108,7 @@ is_testing <- function() {
108108
}
109109
```
110110

111-
It might look like the code appears to still have a runtime dependency on testthat, because of the call to `testthat::skip()`.
111+
It might look like the code still has a runtime dependency on testthat, because of the call to `testthat::skip()`.
112112
But `testthat::skip()` is only executed during a test run, which implies that testthat is installed.
113113

114114
We have mixed feelings about this approach.

vignettes/snapshotting.Rmd

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ snapper$start_file("snapshotting.Rmd", "test")
4242

4343
## Basic workflow
4444

45-
We'll illustrate the basic workflow with a simple function that generates an HTML bullets.
46-
It can optionally include an `id` attribute, which allows you to construct a link directly to that heading.
45+
We'll illustrate the basic workflow with a simple function that generates HTML bullets.
46+
It can optionally include an `id` attribute, which allows you to construct a link directly to that list.
4747

4848
```{r}
4949
bullets <- function(text, id = NULL) {
@@ -198,7 +198,7 @@ test_that("you can't add weird things", {
198198

199199
Just be careful: when you set `error = TRUE`, `expect_snapshot()` checks that at least one expression throws an error, not that every expression throws an error. For example, look above and notice that adding a date and factor generated a warning, not an error.
200200

201-
Snapshot tests are particularly important when testing complex error messages, such as those that you might generate with cli. Here's a more realistic example illustrating how you might test `check_unnamed()`, a function that ensures all arguments in `...` are unnnamed.
201+
Snapshot tests are particularly important when testing complex error messages, such as those that you might generate with cli. Here's a more realistic example illustrating how you might test `check_unnamed()`, a function that ensures all arguments in `...` are unnamed.
202202

203203
```{r}
204204
check_unnamed <- function(..., call = parent.frame()) {

0 commit comments

Comments
 (0)