context('inject')
library(testthatsomemore)
test_that('it correctly injects example values into the local scope', {
inject(list(a = 1, b = 2))
assert(a); assert(b)
expect_equal(a, 1)
expect_equal(b, 2)
})
test_that('it errors when we do not provide a list', {
expect_error(inject(5), 'must be a list')
})
test_that('it errors when an unnamed list is given', {
expect_error(inject(list(5)), 'must be a named list')
})
test_that('it errors when a list with duplicate or empty names is given', {
expect_error(inject(list(a = 1, 2)))
expect_error(inject(list(a = 1, a = 2)))
})
test_that('it can inject into a non-default environment', {
tmp <- new.env(FALSE)
inject(list(a = 1, b = 2), where = tmp)
expect_equal(tmp$a, 1)
expect_equal(tmp$b, 2)
})
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.