expect_equal_to_reference: Expectation: is the object equal to a reference value stored...

Description Usage Arguments Details Examples

Description

This expectation is equivalent to [expect_equal()], except that the expected value is stored in an RDS file instead of being specified literally. This can be helpful when the value is necessarily complex. If the file does not exist then it will be created using the value of the specified object, and subsequent tests will check for consistency against that generated value. The test can be reset by deleting the RDS file.

Usage

1
2
3
expect_equal_to_reference(object, file, ..., info = NULL, label = NULL,
  expected.label = NULL, on.update = getOption("testthat.on.update"),
  on.fail = getOption("testthat.on.fail"))

Arguments

object

object to test

file

The file name used to store the object. Should have an "rds" extension.

...

other values passed to [expect_equal()]

info

extra information to be included in the message (useful when writing tests in loops).

label

For the full form, a label for the expected object, which is used in error messages. Useful to override the default (which is based on the file name), when doing tests in a loop. For the short-cut form, the object label, which is computed from the deparsed object by default.

expected.label

Equivalent of 'label' for shortcut form.

on.update

If non-NULL and if the reference file does not exist, [on.update(o, t)] will be called with 2 parameters:

  1. the new object

  2. a title string composed of the reference file name and the object name

If on.update is NULL and the reference file does not exist, a short message will be printed to alert the tester that the reference file was created instead of tested.

on.fail

If non-NULL and the tested object does not match the reference object, [on.fail(ref, new, title)] will be called with 3 parameters:

  1. the reference object

  2. the new object

  3. a title string composed of the reference file name and the object name

If on.fail is NULL, normal testthat reporting will still occur.

Details

It is important to initialize the reference RDS file within the source package, most likely in the 'tests/testthat' directory. Testing spawned by [devtools::test()/test_file()], for example, will accomplish this. But note that testing spawned by 'R CMD check' and [devtools::check()] will NOT. In the latter cases, the package source is copied to an external location before tests are run. The resulting RDS file will not make its way back into the package source and will not be available for subsequent comparisons.

Examples

1
2
3
4
## Not run: 
expect_equal_to_reference(1, "one.rds")

## End(Not run)

chambm/customProDB documentation built on May 31, 2019, 12:08 p.m.