# context("unit test for create_new_function")
#
# # Helper functions -------------------------------------------------------------
# .set_functions_and_tests_paths <- function(path){
# .create_temp_project_env()
# .project$path_functions <- file.path(path, "code", "R")
# .project$path_tests <- file.path(path, "code", "tests")
# }
#
# # Tests ------------------------------------------------------------------------
# test_that("create_new_function fails when given invalid input arguments", {
# path_temp <- .get_temp_dir()
# .delete_and_create_dir(path_temp)
#
# # No input arguments
# expect_error(create_new_function())
# })
#
# test_that("create_new_function works with unit-test when there are no .project variables", {
# path_temp <- .get_temp_dir()
# .delete_and_create_dir(path_temp)
# .delete_temp_project_env()
#
# expect_null(create_new_function(name = "foo", path = path_temp))
#
# expect_file_exists(file.path(path_temp, "R", "foo.R"))
# expect_file_exists(file.path(path_temp, "tests", "testthat", "test-foo.R"))
# })
#
# test_that("create_new_function works with component-test when there are no .project variables", {
# path_temp <- .get_temp_dir()
# .delete_and_create_dir(path_temp)
# .create_temp_project_env()
#
# expect_null(create_new_function(name = "foo", path = path_temp, test_types = "component"))
#
# expect_file_exists(file.path(path_temp, "R", "foo.R"))
# expect_file_exists(file.path(path_temp, "tests", "component-tests", "test-foo.R"))
# })
#
# test_that("create_new_function works with integration-test when there are no .project variables", {
# path_temp <- .get_temp_dir()
# .delete_and_create_dir(path_temp)
# .create_temp_project_env()
#
# expect_null(create_new_function(name = "foo", path = path_temp, test_types = "integration"))
#
# expect_file_exists(file.path(path_temp, "R", "foo.R"))
# expect_file_exists(file.path(path_temp, "tests", "integration-tests", "test-foo.R"))
# })
#
# test_that("create_new_function works with all test-suite when there are no .project variables", {
# path_temp <- .get_temp_dir()
# .delete_and_create_dir(path_temp)
# .create_temp_project_env()
#
# expect_null(create_new_function(name = "foo", path = path_temp, test_types = "all"))
#
# expect_file_exists(file.path(path_temp, "R", "foo.R"))
# expect_file_exists(file.path(path_temp, "tests", "testthat", "test-foo.R"))
# expect_file_exists(file.path(path_temp, "tests", "component-tests", "test-foo.R"))
# expect_file_exists(file.path(path_temp, "tests", "integration-tests", "test-foo.R"))
# })
#
# test_that("create_new_function works when there are .project variables", {
# path_temp <- .get_temp_dir()
# .delete_and_create_dir(path_temp)
# .set_functions_and_tests_paths(path = path_temp)
#
# expect_null(create_new_function(name = "foo", path = path_temp))
#
# expect_file_exists(file.path(path_temp, "code", "R", "foo.R"))
# expect_file_exists(file.path(path_temp, "code", "tests", "testthat", "test-foo.R"))
# })
#
# test_that("create_new_function replaces template function name with the provided function name", {
# path_temp <- .get_temp_dir()
# .delete_and_create_dir(path_temp)
# .create_temp_project_env()
#
# expect_null(create_new_function(name = "foo", path = path_temp))
#
# function_code <- paste0(readLines(file.path(path_temp, "R", "foo.R")), collapse = "\n")
# expect_false(grepl(pattern = "hello_world", x = function_code))
# expect_true(grepl(pattern = "foo", x = function_code))
#
# unittest_code <- paste0(readLines(file.path(path_temp, "tests", "testthat", "test-foo.R")), collapse = "\n")
# expect_false(grepl(pattern = "hello_world", x = unittest_code))
# expect_true(grepl(pattern = "foo", x = unittest_code))
# })
#
# test_that("create_new_function fails when there is already a function with the same name", {
# path_temp <- .get_temp_dir()
# .delete_and_create_dir(path_temp)
# .set_functions_and_tests_paths(path = path_temp)
#
# expect_null(create_new_function(name = "foo", path = path_temp))
# expect_error(create_new_function(name = "foo", path = path_temp))
# })
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.