Skip to content

Commit

Permalink
Use snapshots for errors that dplyr owns now
Browse files Browse the repository at this point in the history
  • Loading branch information
DavisVaughan committed Dec 14, 2022
1 parent d901487 commit b4733a7
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 8 deletions.
46 changes: 46 additions & 0 deletions tests/testthat/_snaps/step-subset-slice.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,49 @@
# slice_*() checks for empty ...

Code
slice_head(dt, 5)
Condition
Error in `slice_head()`:
! `n` must be explicitly named.
i Did you mean `slice_head(n = 5)`?
Code
slice_tail(dt, 5)
Condition
Error in `slice_tail()`:
! `n` must be explicitly named.
i Did you mean `slice_tail(n = 5)`?
Code
slice_min(dt, x, 5)
Condition
Error in `slice_min()`:
! `n` must be explicitly named.
i Did you mean `slice_min(n = 5)`?
Code
slice_max(dt, x, 5)
Condition
Error in `slice_max()`:
! `n` must be explicitly named.
i Did you mean `slice_max(n = 5)`?
Code
slice_sample(dt, 5)
Condition
Error in `slice_sample()`:
! `n` must be explicitly named.
i Did you mean `slice_sample(n = 5)`?

---

Code
slice_min(dt)
Condition
Error in `slice_min()`:
! `order_by` is absent but must be supplied.
Code
slice_max(dt)
Condition
Error in `slice_max()`:
! `order_by` is absent but must be supplied.

# check_slice_catches common errors

Code
Expand Down
21 changes: 13 additions & 8 deletions tests/testthat/test-step-subset-slice.R
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,19 @@ test_that("arguments to sample are passed along", {

test_that("slice_*() checks for empty ...", {
dt <- lazy_dt(data.frame(x = 1:10))
expect_error(slice_head(dt, 5), class = "rlib_error_dots_nonempty")
expect_error(slice_tail(dt, 5), class = "rlib_error_dots_nonempty")
expect_error(slice_min(dt, x, 5), class = "rlib_error_dots_nonempty")
expect_error(slice_max(dt, x, 5), class = "rlib_error_dots_nonempty")
expect_error(slice_sample(dt, 5), class = "rlib_error_dots_nonempty")

expect_error(slice_min(dt), "missing")
expect_error(slice_max(dt), "missing")

expect_snapshot(error = TRUE, {
slice_head(dt, 5)
slice_tail(dt, 5)
slice_min(dt, x, 5)
slice_max(dt, x, 5)
slice_sample(dt, 5)
})

expect_snapshot(error = TRUE, {
slice_min(dt)
slice_max(dt)
})
})

test_that("slice_*() checks for constant n= and prop=", {
Expand Down

0 comments on commit b4733a7

Please sign in to comment.