There is also a stub
function in the mockery package. It is similar to with_mock
, but it also allows you to cut primitives and functions from the base packages of R.
Example:
g = function(y) y f = function(x) g(x) + 1 test_that('demonstrate stubbing', { # before stubbing expect_equal(f(1), 2) # replace the function 'g' when called from 'f' stub(f, 'g', function(...) 100) expect_equal(f(1), 101) })
source share