Skip to content

Rewrite expectation style #2111

@hadley

Description

@hadley

Drop use of expect() in favour of an if statement that branches to fail(). Every expectation should call succeed() before returning the value.

In most cases, will want to treat fail() like an early return, i.e. instead of

expect_no_success <- function(expr) {
  exp <- capture_success(expr)

  if (!is.null(exp)) {
    fail("Expectation succeeded")
  } else {
    succeed()
  }
  invisible(NULL)
}

Should be

expect_no_success <- function(expr) {
  exp <- capture_success(expr)
  if (!is.null(exp)) {
    fail("Expectation succeeded")
  }
  
  succeed()
  invisible(NULL)
}

And then update the documentation in the custom expectations vignette.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions