diff --git a/R/app.R b/R/app.R index d3f557de8..6791c0216 100644 --- a/R/app.R +++ b/R/app.R @@ -300,7 +300,7 @@ initAutoReloadMonitor <- function(dir) { # > The files are sorted in alphabetical order, on the full path loadHelpers <- function(appDir, envir=globalenv()){ helpersDir <- file.path(appDir, "R") - helpers <- list.files(helpersDir, pattern="\\.[rR]$", recursive=TRUE, full.names=TRUE) + helpers <- list.files(helpersDir, pattern="\\.[rR]$", recursive=FALSE, full.names=TRUE) lapply(helpers, sourceUTF8, envir=envir) } diff --git a/tests/test-helpers/app2-nested/R/nested1/helper.R b/tests/test-helpers/app2-nested/R/helper.R similarity index 100% rename from tests/test-helpers/app2-nested/R/nested1/helper.R rename to tests/test-helpers/app2-nested/R/helper.R diff --git a/tests/test-helpers/app2-nested/R/nested2/helper.R b/tests/test-helpers/app2-nested/R/nested/helper.R similarity index 100% rename from tests/test-helpers/app2-nested/R/nested2/helper.R rename to tests/test-helpers/app2-nested/R/nested/helper.R diff --git a/tests/testthat/test-app.R b/tests/testthat/test-app.R index b815d2612..c6c18fffe 100644 --- a/tests/testthat/test-app.R +++ b/tests/testthat/test-app.R @@ -11,7 +11,7 @@ test_that("helpers are loaded into the right env", { test_that("nested helpers are loaded", { loadHelpers("../test-helpers/app2-nested") expect_equal(helper1, 456) - expect_equal(helper2, "def") + expect_false(exists("helper2")) }) test_that("app with both r/ and R/ prefers R/", { @@ -96,18 +96,15 @@ test_that("app.R is loaded after R/ helpers and into the right envs", { sa$onStop() # Close down to free up resources # Should have seen three calls -- first to two helpers then to app.R - expect_length(calls, 3) - expect_match(calls[[1]][[1]], "nested1/helper\\.R$", perl=TRUE) - expect_match(calls[[2]][[1]], "nested2/helper\\.R$", perl=TRUE) - expect_match(calls[[3]][[1]], "/app\\.R$", perl=TRUE) + expect_length(calls, 2) + expect_match(calls[[1]][[1]], "/helper\\.R$", perl=TRUE) + expect_match(calls[[2]][[1]], "/app\\.R$", perl=TRUE) # Check environments # helpers are loaded into a child of the global env helperEnv1 <- calls[[1]]$envir - helperEnv2 <- calls[[2]]$envir - expect_identical(helperEnv1, helperEnv2) expect_identical(parent.env(helperEnv1), globalenv()) # app.R is sourced into a child environment of the helpers - expect_identical(parent.env(calls[[3]]$envir), helperEnv1) + expect_identical(parent.env(calls[[2]]$envir), helperEnv1) })