Open dimfalk opened 2 years ago
library(mockery)
# set up the mock
mock_download_file <- mock_function(return_value = TRUE)
mock_download_file(file = "test.txt", url = "http://example.com/test.txt")
# call the function that uses download.file
your_function_to_test()
# check the output
expect_true(mock_download_file.calls$file[1] == "test.txt")
expect_true(mock_download_file.calls$url[1] == "http://example.com/test.txt")
library(mockery)
mocked_response <- list(status = 200, body = "Mocked response")
# set up the mock
mock_api_call <- mockery::mock_function(return_value = mocked_response)
# make the request
response <- mock_api_call()
# check the response
response
https://github.com/ropensci/vcr
https://github.com/ropensci/webmockr/
https://github.com/r-lib/mockery
https://github.com/nealrichardson/httptest
https://github.com/nealrichardson/httptest2