inst/examples/table/tests/testthat/steps/steps.R

read_table <- function(x) {
  x |>
    dplyr::mutate_all(as.numeric)
}

given("I have a table", function(table, context) {
  context$table <- table |>
    read_table()
})

when("I multiply {word} column by {int}", function(column, factor, context) {
  context$table <- context$table |>
    dplyr::mutate(dplyr::across({{ column }}, \(x) x * factor))
})

then("I should see the following table", function(table, context) {
  table <- table |>
    read_table()

  expect_equal(
    context$table,
    table
  )
})

Try the cucumber package in your browser

Any scripts or data that you put into this service are public.

cucumber documentation built on June 30, 2024, 1:07 a.m.