inst/examples/box_support/tests/testthat/steps/addition.R

box::use(
  R/addition[add],
  cucumber[
    given,
    when,
    then,
  ]
)

when("I add {int} and {int}", function(x, y, context) {
  context$result <- add(x, y)
})

then("the result is {int}", function(expected, context) {
  expect_equal(context$result, expected)
})

when("I add {int} and {float}", function(x, y, context) {
  context$result <- add(x, y)
})

when("I add {float} and {float}", function(x, y, context) {
  context$result <- add(x, y)
})

when("I add {float} and {string}", function(x, y, context) {
  context$lazy_result <- \() add(x, y)
})

then("the result is {float}", function(expected, context) {
  expect_equal(context$result, expected)
})

then("the result is an error", function(context) {
  expect_error(context$lazy_result())
})

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.