Skip to content

Commit be516a9

Browse files
committed
Use local_mocked_bindings()
Closes #456, closes #434
1 parent 1d137e6 commit be516a9

File tree

5 files changed

+23
-42
lines changed

5 files changed

+23
-42
lines changed

DESCRIPTION

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ Suggests:
3434
curl,
3535
dplyr (>= 1.0.0),
3636
knitr,
37-
mockr,
3837
rmarkdown,
3938
spelling,
4039
testthat (>= 3.1.5)

inst/WORDLIST

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ ing
4646
lifecycle
4747
lowerCamel
4848
magrittr
49-
mockr
5049
pkgdown
5150
pre
5251
programmatically

tests/testthat/helper.R

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,6 @@ skip_if_no_token <- function() {
1313
testthat::skip_if_not(drive_has_token(), "No Drive token")
1414
}
1515

16-
with_mock <- function(..., .parent = parent.frame()) {
17-
mockr::with_mock(..., .parent = .parent, .env = "googledrive")
18-
}
19-
2016
# usage:
2117
# test_fixture("something.rds")
2218
test_fixture <- function(name) testthat::test_path("test-fixtures", name)

tests/testthat/test-drive_get_path.R

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ test_that("get_last_path_part() works", {
2323
})
2424

2525
test_that("resolve_paths() works, basic scenarios", {
26+
local_mocked_bindings(
27+
root_id = function() ""
28+
)
29+
2630
# a -- b -- c -- d
2731
# ??? -- e
2832
dr_folder <-
@@ -43,22 +47,12 @@ test_that("resolve_paths() works, basic scenarios", {
4347
id = "4",
4448
drive_resource = list(list(kind = "drive#file", parents = list(list("3"))))
4549
)
46-
with_mock(
47-
root_id = function() "",
48-
{
49-
out <- resolve_paths(as_dribble(x), ancestors)
50-
}
51-
)
50+
out <- resolve_paths(as_dribble(x), ancestors)
5251
expect_equal(out$path, "a/b/c/d")
5352

5453
# target is a folder
5554
x$drive_resource <- list(c(dr_folder, parents = list(list("3"))))
56-
with_mock(
57-
root_id = function() "",
58-
{
59-
out <- resolve_paths(as_dribble(x), ancestors)
60-
}
61-
)
55+
out <- resolve_paths(as_dribble(x), ancestors)
6256
expect_equal(out$path, "a/b/c/d/")
6357

6458
# target's parent is not among the elders
@@ -67,16 +61,15 @@ test_that("resolve_paths() works, basic scenarios", {
6761
id = "4",
6862
drive_resource = list(list(kind = "drive#file", parents = list(list("9"))))
6963
)
70-
with_mock(
71-
root_id = function() "",
72-
{
73-
out <- resolve_paths(as_dribble(x), ancestors)
74-
}
75-
)
64+
out <- resolve_paths(as_dribble(x), ancestors)
7665
expect_equal(out$path, "e")
7766
})
7867

7968
test_that("resolve_paths() works, with some name duplication", {
69+
local_mocked_bindings(
70+
root_id = function() ""
71+
)
72+
8073
# name(id)
8174
# ___~(1) __
8275
# / \ \
@@ -110,12 +103,8 @@ test_that("resolve_paths() works, with some name duplication", {
110103
list(kind = "drive#file", parents = list(list("7")))
111104
)
112105
)
113-
with_mock(
114-
root_id = function() "",
115-
{
116-
out <- resolve_paths(as_dribble(x), ancestors)
117-
}
118-
)
106+
out <- resolve_paths(as_dribble(x), ancestors)
107+
119108
expect_equal(out$path[1], "~/a/b/c")
120109
expect_equal(out$path[2], "~/b/a/d")
121110
})

tests/testthat/test-utils-paths.R

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -136,18 +136,16 @@ test_that("rationalize_path_name() won't hit API if we can infer `path` is a fol
136136
})
137137

138138
test_that("rationalize_path_name() populates `path` and `name` and correctly", {
139-
with_mock(
140-
confirm_clear_path = function(path, name) NULL,
141-
{
142-
expect_identical(
143-
rationalize_path_name(path = "FILE_NAME", name = NULL),
144-
list(path = NULL, name = "FILE_NAME")
145-
)
146-
expect_identical(
147-
rationalize_path_name(path = "PARENT_FOLDER/FILE_NAME", name = NULL),
148-
list(path = "PARENT_FOLDER/", name = "FILE_NAME")
149-
)
150-
}
139+
local_mocked_bindings(
140+
confirm_clear_path = function(path, name) NULL
141+
)
142+
expect_identical(
143+
rationalize_path_name(path = "FILE_NAME", name = NULL),
144+
list(path = NULL, name = "FILE_NAME")
145+
)
146+
expect_identical(
147+
rationalize_path_name(path = "PARENT_FOLDER/FILE_NAME", name = NULL),
148+
list(path = "PARENT_FOLDER/", name = "FILE_NAME")
151149
)
152150
})
153151

0 commit comments

Comments
 (0)