context("integration tests for project deployment")
#' SCENARIO: Instantiate and initialise a new project
#'
#' GIVEN path AND name of a new project
#'
#' WHEN deploy_project is called and the project is fetched by .proj file
#'
#' THEN the paths of the project are available in an environment called .project
#'
test_that("the package allows to instantiate and initialise a new project", {
###########
## Setup ##
###########
## Create a temporary folder
path_temp <- getwd()
while (length(grep("test", path_temp))>0) path_temp <- dirname(path_temp)
path_temp <- file.path(path_temp, "temp")
unlink(path_temp, recursive = TRUE)
dir.create(path_temp, showWarnings = FALSE, recursive = TRUE)
## Define project name and location
path <- path_temp
name <- "project-template"
path_project <- file.path(path, name)
##################################
## Step 1: Deploy a New Project ##
##################################
expect_null(
callr::r(function(path_project){
#################
## Instantiate ##
#################
library(tidylab.deployment)
deploy_project(name = basename(path_project),
path = dirname(path_project))
###########
## Tests ##
###########
stopifnot(dir.exists(path_project))
############
## Return ##
############
return(invisible())
}, list(path_project), show = TRUE)# end callr::r step 1
)
###########################################
## Step 2: Load Project in a New Session ##
###########################################
expect_null(
callr::r(function(path_project){
################
## Initialise ##
################
setwd(path_project)
## Make sure it's a new session
stopifnot(isFALSE(exists(".project")))
## Start the project via the Rprofile file
target <- file.path(path_project, ".Rprofile")
source(target)
###########
## Tests ##
###########
## .project environment has been established
stopifnot(isTRUE(exists(".project")))
## The project root is correct
stopifnot(identical(getwd(), .project$path_project))
############
## Return ##
############
return(invisible())
}, list(path_project), show = TRUE)# end callr::r step 2
)
####################################################
## Step 3: Create a Function with Full Test-Suite ##
####################################################
expect_null(
callr::r(function(path_project){
setwd(path_project)
target <- file.path(path_project, ".Rprofile")
source(target)
tidylab.deployment::create_new_function(name = "bar", path = path_project, test_types = "all")
stopifnot(file.exists(file.path(.project$path_functions, "bar.R")))
}, list(path_project), show = TRUE)# end callr::r step 3
)
})
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.