expect_equal_to_reference {testthat} | R Documentation |
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.
expect_equal_to_reference(object, file, ..., info = NULL, label = NULL, expected.label = NULL)
object |
object to test |
file |
The file name used to store the object. Should have an "rds" extension. |
... |
other values passed to |
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 |
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.
Other expectations: comparison-expectations
,
equality-expectations
,
expect_length
, expect_match
,
expect_named
,
inheritance-expectations
,
logical-expectations
,
output-expectations
## Not run: expect_equal_to_reference(1, "one.rds") ## End(Not run)