Helper Defined Inside a Test

A hyper-local helper like trunc() is particularly useful when it allows you to fit all the important business for each expectation on one line.

# from stringr (actually)
test_that("truncations work for all sides", {

  trunc <- function(direction) str_trunc(
    "This string is moderately long",
    width = 20

  expect_equal(trunc("right"),   "This string is mo...")
  expect_equal(trunc("left"),    "...s moderately long")
  expect_equal(trunc("center"),  "This stri...ely long")

A helper like trunc() is yet another place where you can introduce a bug.