stubing does not propagate into partialised function
lorenzwalthert opened this issue · comments
Lorenz Walthert commented
Not sure there is a way to overcome this limitation but it would make the package more useful if you would allow to also mock functions that were partialised with purrr like this:
library(testthat)
plus <- function(x = 0, y = 0) {
x + y
}
x_times_two <- function(x, y) {
plus(x, x)
}
contains_plus <- purrr::partial(x_times_two, x = 3) # contains a call to plus()
mockery::stub(
x_times_two,
"plus", function(x, y) -1111
)
expect_equal(contains_plus(y = 2), -1111)
#> Error: contains_plus(y = 2) not equal to -1111.
#> 1/1 mismatches
#> [1] 6 - -1111 == 1117
mockery::stub(
contains_plus,
"plus", function(x, y) -1111
)
expect_equal(contains_plus(y = 2), -1111)
#> Error: contains_plus(y = 2) not equal to -1111.
#> 1/1 mismatches
#> [1] 6 - -1111 == 1117
Created on 2020-12-21 by the reprex package (v0.3.0)
Hadley Wickham commented
I'm pretty sure testthat::local_mocked_bindings()
resolves this issue too.