From e542155639bbb73b97a7dc343022e9c6f962c47c Mon Sep 17 00:00:00 2001 From: Will Beasley Date: Wed, 14 Aug 2019 15:25:31 -0500 Subject: [PATCH] bad URIs now throw an error --- DESCRIPTION | 4 ++-- tests/test-all.R | 2 +- tests/testthat/test-variables.R | 21 ++++++++++++--------- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 757f0067..6434d5b7 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -17,8 +17,8 @@ Authors@R: c(person("Will", "Beasley", role = c("aut", "cre"), email = "rparrish@flightweb.com"), person("Benjamin", "Nutter", role = "ctb"), person("Andrew", "Peters", role = "ctb"), person("Hao", "Zhu", - role = "ctb"), - comment = c(ORCID = '0000-0002-3386-6076')) + role = "ctb", + comment = c(ORCID = '0000-0002-3386-6076'))) Author: Will Beasley [aut, cre], David Bard [ctb], Thomas Wilson [ctb], diff --git a/tests/test-all.R b/tests/test-all.R index 9bb0f7e1..283914c2 100644 --- a/tests/test-all.R +++ b/tests/test-all.R @@ -1,4 +1,4 @@ -#Modeled after the R6 testing structure: https://github.com/wch/R6/blob/master/tests/testthat.R +# Modeled after the R6 testing structure: https://github.com/wch/R6/blob/master/tests/testthat.R library(testthat) library(REDCapR) diff --git a/tests/testthat/test-variables.R b/tests/testthat/test-variables.R index f3a00162..c58e8300 100644 --- a/tests/testthat/test-variables.R +++ b/tests/testthat/test-variables.R @@ -53,21 +53,24 @@ test_that("All Records -Default", { test_that("Bad URI", { testthat::skip_on_cran() - bad_uri <- "google.com" + bad_uri <- "https://aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.com" expected_data_frame <- structure(list(), .Names = character(0), row.names = integer(0), class = "data.frame") - expected_outcome_message <- "The REDCapR variable retrieval was not successful\\..+?Error 405 \\(Method Not Allowed\\).+" + expected_outcome_message <- "Failed to connect to aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.com port 44" # + # "The REDCapR variable retrieval was not successful\\..+?Error 405 \\(Method Not Allowed\\).+" # expected_outcome_message <- "(?s)The REDCapR variable retrieval was not successful\\..+?.+" - expect_message( + expect_error( returned_object <- redcap_variables(redcap_uri=bad_uri, token=credential$token), regexp = expected_outcome_message ) - expected_outcome_message <- paste0("(?s)", expected_outcome_message) - expect_equal(returned_object$data, expected=expected_data_frame, label="The returned data.frame should be correct") # dput(returned_object$data) - expect_equal(returned_object$status_code, expected=405L) - # expect_equivalent(returned_object$raw_text, expected="") # dput(returned_object$raw_text) - expect_match(returned_object$outcome_message, regexp=expected_outcome_message, perl=TRUE) - expect_false(returned_object$success) + # Now thean error is thrown with a bad URI. + # expected_outcome_message <- paste0("(?s)", expected_outcome_message) + # + # expect_equal(returned_object$data, expected=expected_data_frame, label="The returned data.frame should be correct") # dput(returned_object$data) + # expect_equal(returned_object$status_code, expected=405L) + # # expect_equivalent(returned_object$raw_text, expected="") # dput(returned_object$raw_text) + # expect_match(returned_object$outcome_message, regexp=expected_outcome_message, perl=TRUE) + # expect_false(returned_object$success) })