1
1
test_that(" user_categorisation works with valid input" , {
2
- # create a mock object that returns user inputs in sequence
3
- mock_readline <- mockery :: mock(" 3" , " This is a note" , " n" )
2
+
4
3
# replace `readline` function within the `user_categorisation` function with
5
- # the `mock_readline` mock object
6
- mockery :: stub(user_categorisation , " readline" , mock_readline )
4
+ # the `helper-mock_factory.R` mock object
5
+ local_mocked_bindings(
6
+ readline = helper_mock(" 3" , " This is a note" , " n" )
7
+ )
7
8
8
9
response <- user_categorisation(var = " Variable1" ,
9
10
desc = " Description1" ,
@@ -12,11 +13,9 @@ test_that("user_categorisation works with valid input", {
12
13
})
13
14
14
15
test_that(" user_categorisation handles invalid input and then valid input" , {
15
- # create a mock object that returns invalid input first, then valid input
16
- mock_readline <- mockery :: mock(" 6" , " 3" , " This is a note" , " n" )
17
- # replace `readline` function within the `user_categorisation` function with
18
- # the `mock_readline` mock object
19
- mockery :: stub(user_categorisation , " readline" , mock_readline )
16
+ local_mocked_bindings(
17
+ readline = helper_mock(" 6" , " 3" , " This is a note" , " n" )
18
+ )
20
19
21
20
response <- user_categorisation(var = " Variable1" ,
22
21
desc = " Description1" ,
@@ -25,12 +24,9 @@ test_that("user_categorisation handles invalid input and then valid input", {
25
24
})
26
25
27
26
test_that(" user_categorisation handles multiple valid inputs" , {
28
- # create a mock object that returns multiple valid inputs
29
- mock_readline <- mockery :: mock(" 3,4" , " This is another note" , " n" )
30
- # replace `readline` function within the `user_categorisation` function with
31
- # the `mock_readline` mock object
32
- mockery :: stub(user_categorisation , " readline" , mock_readline )
33
-
27
+ local_mocked_bindings(
28
+ readline = helper_mock(" 3,4" , " This is another note" , " n" )
29
+ )
34
30
response <- user_categorisation(var = " Variable1" ,
35
31
desc = " Description1" ,
36
32
type = " Type1" , domain_code_max = 5 )
@@ -39,12 +35,10 @@ test_that("user_categorisation handles multiple valid inputs", {
39
35
})
40
36
41
37
test_that(" user_categorisation handles re-do input" , {
42
- # create a mock object that returns inputs including re-do
43
- mock_readline <- mockery :: mock(" 3" , " This is a note" , " y" , " 4" ,
44
- " Another note" , " n" )
45
- # replace `readline` function within the `user_categorisation` function with
46
- # the `mock_readline` mock object
47
- mockery :: stub(user_categorisation , " readline" , mock_readline )
38
+ local_mocked_bindings(
39
+ readline = helper_mock(" 3" , " This is a note" , " y" , " 4" ,
40
+ " Another note" , " n" )
41
+ )
48
42
49
43
response <- user_categorisation(var = " Variable1" ,
50
44
desc = " Description1" ,
0 commit comments