Description Usage Arguments Details Examples
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.
1 2 3 |
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:
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:
If on.fail is NULL, normal testthat reporting will still occur. |
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.
1 2 3 4 | ## Not run:
expect_equal_to_reference(1, "one.rds")
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.