-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.R
46 lines (45 loc) · 1.64 KB
/
test.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#' @importFrom fs dir_ls
#' @importFrom purrr map walk
.default_steps_loader <- function(steps_dir) {
steps_files <- dir_ls(steps_dir, glob = "*.R$", type = "file")
walk(steps_files, source)
get_steps()
}
#' Run all Cucumber tests
#'
#' This command runs all Cucumber tests. It takes all .feature files
#' from the \code{features_dir} and runs them using the steps from the \code{steps_dir}.
#'
#' @param features_dir A character string of the directory containing the feature files.
#' @param steps_dir A character string of the directory containing the step files.
#' @param steps_loader A function that loads the steps implementations. By default it sources all files
#' from the \code{steps_dir} using the built-in mechanism. You can provide your own function to load
#' the steps. The function should take one argument, which will be the \code{steps_dir}
#' and return a list of steps.
#' @return None, function called for side effects.
#'
#' @export
#' @importFrom fs dir_ls
#' @importFrom purrr map walk
#' @importFrom checkmate assert_directory_exists assert_function assert_list
#' @importFrom withr defer
test <- function(
features_dir,
steps_dir,
steps_loader = .default_steps_loader
) {
assert_directory_exists(features_dir)
assert_directory_exists(steps_dir)
assert_function(steps_loader, nargs = 1)
defer({
clear_steps()
set_default_parameters()
})
steps <- steps_loader(steps_dir)
assert_list(steps, types = "step")
feature_files <- dir_ls(features_dir, glob = "*.feature$", type = "file")
feature_files |>
map(readLines) |>
map(normalize_feature) |>
walk(run, steps = steps, parameters = get_parameters())
}