Closed jcpsantiago closed 4 years ago
I see a couple of options, not mutually exclusive:
expect_POST(...)
to assert that you're requesting at the right endpoint@jcpsantiago you've probably solved this already but leaving it here for folks looking for a solution (I just ran into this problem). I used the mocking approach successfully and stubbbed out Sys.time
using the mockery package. The key was to set the depth
argument as well because of the nested nature of my functions (could be different for you).
with_mock_api({
test_that("success generates message", {
time_stub <- "2020-03-14 12:51:02 CET"
# depth = 3 because gen_action_ is called further down
mockery::stub(gen_action_, "Sys.time", time_stub, depth = 3)
expect_message(
myfunction(...)
)
})
})
I need to do
POST
requests which include fields that change over time like timestamp, r version, package versions etc. The current logic of hashing body prevents me from usingwith_mock_api
because it never finds the correct mock file. Is there already a way of bypassing this? Looking at the source code there seems to be no option for it.