How to create expectations in testthat?

A naive approach to writing custom expectations from existing expectations:

expect_between <- function (x, lo, hi) {
    expect_lte(lo, x)
    expect_lte(x, hi)
}

      

but that doesn't work with expect_failure

since it expect_failure

captures the first wait.

expect_between(0.5, 0, 1)                  # PASSES
expect_between(-99, 0, 1)                  # FAILS
expect_between(99, 0, 1)                   # FAILS
expect_failure(expect_between(-99, 0, 1))  # PASSES
expect_failure(expect_between(99, 0, 1))   # FAILS <--- the problem

      

What is the correct way to make expectations when writing custom expectations so that they still play well with expect_failure

?

+3


source to share





All Articles