nealrichardson / httptest

A Test Environment for HTTP Requests in R
https://enpiar.com/r/httptest/
Other
79 stars 10 forks source link

How to squelch "No encoding supplied: defaulting to UTF-8." for with_mock_dir()? #75

Closed maelle closed 1 year ago

maelle commented 1 year ago

In a test with with_mock_dir() I get the message "No encoding supplied: defaulting to UTF-8." that I see is squelched for capture_requests() but not in this context.

Repo https://github.com/maelle/msghttptest Test https://github.com/maelle/msghttptest/blob/main/tests/testthat/test-msg.R Snap https://github.com/maelle/msghttptest/blob/main/tests/testthat/_snaps/msg.md Mock file https://github.com/maelle/msghttptest/blob/main/tests/testthat/pr0/api.github.com/user.json

nealrichardson commented 1 year ago

That message comes from httr:::guess_encoding, which is called in httr::content(x, as = "text") if the content-type header doesn't specify a charset. All instances of httr::content() in httptest are wrapped in suppressMessages() to handle this.

Your gh_whoami() test code calls gh:::gh_process_response, which calls httr::content. I suspect that's where the message is being raised, not from httptest.

maelle commented 1 year ago

Thanks a ton and sorry!