context("unit test for deploy-project")
# deploy_project ---------------------------------------------------------------
test_that("deploy_project creates the project folder structure", {
path_temp <- .get_temp_dir()
.delete_and_create_dir(path_temp)
#############################
## Invalid Input Arguments ##
#############################
## Case 1: Invalid path
path <- "xxx"
name <- "project-template"
expect_error(deploy_project(name = name, path = path))
###########################
## Valid Input Arguments ##
###########################
## Case 1: Valid path and name
unlink(path_temp, recursive = TRUE)
path <- path_temp
name <- "project-template"
expect_null(deploy_project(name = name, path = path))
k_paths <- c(file.path(path, name, "code"),
file.path(path, name, "code", "R"),
file.path(path, name, "code", "tests"),
file.path(path, name, "data"),
file.path(path, name, "docs"),
file.path(path, name, "models"))
for(k_path in k_paths){
expect_true(dir.exists(k_path), label = k_path)
expect_true(file.exists(file.path(k_path, ".md")), label = file.path(k_path, ".md"))
}
## Case 2: Valid path and problematic name (spaces and capital letters)
unlink(path_temp, recursive = TRUE)
path <- path_temp
name <- "project template"
expect_null(deploy_project(name = name, path = path))
expect_true(dir.exists(file.path(path, "project-template")))
})
test_that("deploy_project creates the DESCRIPTION file", {
path_temp <- .get_temp_dir()
.delete_and_create_dir(path_temp)
## Deploy the project
path <- path_temp
name <- "project-template"
expect_null(deploy_project(name = name, path = path))
###########
## Tests ##
###########
## Get project DESCRIPTION
expect_silent(description_obj <- desc::description$new(file.path(path, name)))
## Get project name
expect_identical(description_obj$get_field("Package"), "project.template")
## Get project URL
expect_true(description_obj$get_field("URL") == "{{ URL }}")
## Get project authors
author_1 <- person("Bilbo", "Baggins", NULL, "bilbo@the-shire.co.nz", c("aut", "cre"))
author_2 <- person("Peregrin", "Took", NULL, "peregrin@the-shire.co.nz", c("ctb"))
expect_identical(description_obj$get_authors(), c(author_1, author_2))
## Get project maintainer
expect_true(description_obj$get_maintainer() != "{{ Maintainer }}")
## Get project license
expect_identical(description_obj$get_field("License"), "MIT + file LICENSE")
expect_true(file.exists(file.path(path, name, "LICENSE")))
## Get project packages
requirements <- list()
requirements$type <- c("Imports", "Imports", "Imports", "Imports", "Suggests", "Suggests")
requirements$package <- c("magrittr", "remotes", "tidyverse", "tidylab" ,"testthat", "covr")
requirements$version <- c(">= 1.5", ">= 2.0.2", ">= 1.2.1", "*", "*", "*")
requirements <- as.data.frame(requirements, stringsAsFactors = FALSE)
expect_identical(description_obj$get_deps(), requirements)
expect_length(description_obj$get_remotes(), 1)
})
test_that("deploy_project creates config.yml", {
path_temp <- .get_temp_dir()
.delete_and_create_dir(path_temp)
## Deploy the project
path <- path_temp
name <- "project-template"
expect_null(deploy_project(name = name, path = path))
###########
## Tests ##
###########
## Setup
path_project <- file.path(path, name)
setwd(path_project)
## Read config file
expect_silent(tags <- yaml::read_yaml(file.path(path_project, "config.yml")))
## Global variable point at the project location
expect_identical(eval(parse(text = tags$options$path_project)), path_project)
expect_identical(eval(parse(text = tags$options$path_code)), file.path(path_project, "code"))
## Cleanup
setwd(dirname(path_temp))
})
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.