-
Notifications
You must be signed in to change notification settings - Fork 4
Open
Description
I was thinking about how we could test and I thought about the idea of mocking curl_fetch_memory.
Check this out:
curl_env <- environment(curl::curl_fetch_memory)
old_curl_fetch_memory <- curl::curl_fetch_memory
unlockBinding(quote(curl_fetch_memory), curl_env)
assign("curl_fetch_memory",
function(...) list(
response_code = 200,
content = charToRaw("Hello Curled!")),
envir = curl_env)
a <- curl::curl_fetch_memory("http://whatever")
print(a)
#> $response_code
#> [1] 200
#>
#> $content
#> [1] 48 65 6c 6c 6f 20 43 75 72 6c 65 64 21
print(rawToChar(a$content))
#> [1] "Hello Curled!"
assign("curl_fetch_memory",
old_curl_fetch_memory,
envir = curl_env)
lockBinding(quote(curl_fetch_memory),
curl_env)
a <- curl::curl_fetch_memory("http://whatever")
#> Error in curl::curl_fetch_memory("http://whatever"): Could not resolve host: whateverCreated on 2020-07-02 by the reprex package (v0.3.0)
Metadata
Metadata
Assignees
Labels
No labels