| stub {mockery} | R Documentation |
The result of calling stub is that, when where
is invoked and when it internally makes a call to what,
how is going to be called instead.
stub(where, what, how, depth = 1)
where |
Function to be called that will in turn call
|
what |
Name of the function you want to stub out (a
|
how |
Replacement function (also a |
depth |
Specifies the depth to which the function should be stubbed |
This is much more limited in scope in comparison to
with_mock which effectively replaces
what everywhere. In other words, when using with_mock
and regardless of the number of intermediate calls, how is
always called instead of what. However, using this API,
the replacement takes place only for a single function where
and only for calls originating in that function.
f <- function() TRUE g <- function() f() stub(g, 'f', FALSE) # now g() returns FALSE because f() has been stubbed out g()