Skip to content

Commit fdde60a

Browse files
add test to make sure you can pass arguments to model specs (#747)
* add test to make sure you can pass arguments to model specs * fix a bad merge Co-authored-by: Max Kuhn <mxkuhn@gmail.com>
1 parent 301cf72 commit fdde60a

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

tests/testthat/test_misc.R

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,28 @@ test_that('model type functions message informatively with unknown implementatio
115115
)
116116
})
117117

118+
119+
test_that('arguments can be passed to model spec inside function', {
120+
f <- function(k = 5) {
121+
nearest_neighbor(mode = "regression", neighbors = k) %>%
122+
fit(mpg ~ ., data = mtcars)
123+
}
124+
125+
exp_res <- nearest_neighbor(mode = "regression", neighbors = 5) %>%
126+
fit(mpg ~ ., data = mtcars)
127+
128+
expect_error(
129+
fun_res <- f(),
130+
NA
131+
)
132+
133+
expect_equal(exp_res$fit[-c(8, 9)], fun_res$fit[-c(8, 9)])
134+
})
135+
136+
118137
test_that('set_engine works as a generic', {
119138
expect_snapshot(error = TRUE,
120-
set_engine(mtcars, "rpart")
139+
set_engine(mtcars, "rpart")
121140
)
141+
122142
})

0 commit comments

Comments
 (0)