Skip to content

Commit

Permalink
Add comment to clarify without_internet usage in an example (#68)
Browse files Browse the repository at this point in the history
* add comment to example to clarify without_internet usage

* expand expect_verb description

* simplify test helper function with getRversion()
  • Loading branch information
ErdaradunGaztea authored Apr 22, 2022
1 parent 78ddf44 commit cb1739c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
7 changes: 7 additions & 0 deletions R/expect-request.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#' Expectations for mocked HTTP requests
#'
#' @description
#' The mock contexts in `httptest` can raise errors or messages when requests
#' are made, and those (error) messages have three
#' elements, separated by space: (1) the request
Expand All @@ -8,6 +9,11 @@
#' These verb-expectation functions look for this message shape. `expect_PUT`,
#' for instance, looks for a request message that starts with "PUT".
#'
#' This means that `expect_verb` functions won't work outside of mock context,
#' as no error would be raised while making a request. Thus, any `expect_verb`
#' function should be wrapped inside a mocking function like
#' [without_internet()], as shown in the examples.
#'
#' @param object Code to execute that may cause an HTTP request
#' @param url character: the URL you expect a request to be made to. Default is
#' an empty string, meaning that you can just assert that a request is made with
Expand All @@ -27,6 +33,7 @@
#' @return A `testthat` 'expectation'.
#' @examples
#' library(httr)
#' # without_internet provides required mock context for expectations
#' without_internet({
#' expect_GET(
#' GET("http://httpbin.org/get"),
Expand Down
6 changes: 6 additions & 0 deletions man/expect_verb.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions tests/testthat/setup.R
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ install_testpkg <- function(pkg, lib = tempfile()) {
}

skip_on_R_older_than <- function(version) {
r <- R.Version()
if (utils::compareVersion(paste(r$major, r$minor, sep = "."), version) < 0) {
if (getRversion() < version) {
skip(paste("Requires R >=", version))
}
}
Expand Down

0 comments on commit cb1739c

Please sign in to comment.