testthat (version 1.0.2)

expect_equal_to_reference: Expectation: is the object equal to a reference value stored in a file?

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

expect_equal_to_reference(object, file, ..., info = NULL, label = NULL,
  expected.label = NULL)

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 deparse
expected.label
Equivalent of label for shortcut form.

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(), 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.

See Also

Other expectations: comparison-expectations, equality-expectations, expect_length, expect_match, expect_named, inheritance-expectations, logical-expectations, output-expectations

Examples

Run this code
expect_equal_to_reference(1, "one.rds")

Run the code above in your browser using DataLab