|
56 | 56 | #' })
|
57 | 57 |
|
58 | 58 | describe <- function(description, code) {
|
59 |
| - is_invalid_description <- function(description) { |
60 |
| - !is.character(description) || length(description) != 1 || |
61 |
| - nchar(description) == 0 |
62 |
| - } |
63 |
| - |
64 |
| - if (is_invalid_description(description)) { |
65 |
| - stop("description must be a string of at least length 1") |
66 |
| - } |
| 59 | + check_string(description, allow_empty = FALSE) |
| 60 | + describe_description <- description |
67 | 61 |
|
68 | 62 | # prepares a new environment for each it-block
|
69 | 63 | describe_environment <- new.env(parent = parent.frame())
|
70 |
| - describe_environment$it <- function(it_description, it_code = NULL) { |
71 |
| - if (is_invalid_description(it_description)) { |
72 |
| - stop("it-description must be a string of at least length 1") |
73 |
| - } |
74 |
| - if (missing(it_code)) return() |
| 64 | + describe_environment$it <- function(description, code = NULL) { |
| 65 | + check_string(description, allow_empty = FALSE) |
| 66 | + code <- substitute(code) |
75 | 67 |
|
76 |
| - test_description <- paste0(description, ": ", it_description) |
77 |
| - test_code( |
78 |
| - test_description, |
79 |
| - substitute(it_code), |
80 |
| - env = describe_environment, |
81 |
| - skip_on_empty = FALSE |
82 |
| - ) |
| 68 | + description <- paste0(describe_description, ": ", description) |
| 69 | + describe_it(description, code, describe_environment) |
83 | 70 | }
|
84 | 71 |
|
85 | 72 | eval(substitute(code), describe_environment)
|
86 | 73 | invisible()
|
87 | 74 | }
|
| 75 | + |
| 76 | +describe_it <- function(description, code, env = parent.frame()) { |
| 77 | + local_test_context() |
| 78 | + |
| 79 | + test_code( |
| 80 | + description, |
| 81 | + code, |
| 82 | + env = env, |
| 83 | + skip_on_empty = FALSE |
| 84 | + ) |
| 85 | +} |
| 86 | + |
| 87 | +#' @export |
| 88 | +#' @rdname describe |
| 89 | +it <- function(description, code = NULL) { |
| 90 | + check_string(description, allow_empty = FALSE) |
| 91 | + |
| 92 | + code <- substitute(code) |
| 93 | + describe_it(description, code) |
| 94 | +} |
0 commit comments