Skip to content

Commit d947142

Browse files
authored
Allow unquoting first arg for expect_s4_class() (#2065)
Fixes #2064
1 parent bfde1ce commit d947142

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# testthat (development version)
22

3+
* `expect_s4_class()` now supports unquoting (@stibu81, #2064).
34
* `it()` now finds the correct evaluation environment in more cases (@averissimo, #2085).
45
* Fixed an issue preventing compilation from succeeding due to deprecation / removal of `std::uncaught_exception()` (@kevinushey, #2047).
56

R/expect-inheritance.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ expect_s7_class <- function(object, class) {
125125
#' @rdname inheritance-expectations
126126
expect_s4_class <- function(object, class) {
127127
act <- quasi_label(enquo(object), arg = "object")
128-
act_val_lab <- format_class(methods::is(object))
128+
act$class <- format_class(methods::is(act$val))
129129
exp_lab <- format_class(class)
130130

131131
if (identical(class, NA)) {
@@ -139,7 +139,7 @@ expect_s4_class <- function(object, class) {
139139
} else {
140140
expect(
141141
methods::is(act$val, class),
142-
sprintf("%s inherits from %s not %s.", act$lab, act_val_lab, exp_lab)
142+
sprintf("%s inherits from %s not %s.", act$lab, act$class, exp_lab)
143143
)
144144
}
145145
} else {

tests/testthat/test-expect-inheritance.R

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,12 @@ test_that("expect_s3_class allows unquoting of first argument", {
6262
})
6363

6464

65+
test_that("expect_s4_class allows unquoting of first argument", {
66+
cls <- methods::setClass("new_class", slots = c("a" = "numeric"))
67+
obj <- methods::new("new_class", a = 3)
68+
expect_success(expect_s4_class(!! rlang::quo(obj), "new_class"))
69+
})
70+
6571
# expect_s7_class --------------------------------------------------------
6672

6773
test_that("checks its inputs", {

0 commit comments

Comments
 (0)