diff --git a/R/expect-inheritance.R b/R/expect-inheritance.R index 10677a556..199b32d3c 100644 --- a/R/expect-inheritance.R +++ b/R/expect-inheritance.R @@ -125,7 +125,7 @@ expect_s7_class <- function(object, class) { #' @rdname inheritance-expectations expect_s4_class <- function(object, class) { act <- quasi_label(enquo(object), arg = "object") - act_val_lab <- format_class(methods::is(object)) + act$class <- format_class(methods::is(act$val)) exp_lab <- format_class(class) if (identical(class, NA)) { @@ -139,7 +139,7 @@ expect_s4_class <- function(object, class) { } else { expect( methods::is(act$val, class), - sprintf("%s inherits from %s not %s.", act$lab, act_val_lab, exp_lab) + sprintf("%s inherits from %s not %s.", act$lab, act$class, exp_lab) ) } } else { diff --git a/tests/testthat/test-expect-inheritance.R b/tests/testthat/test-expect-inheritance.R index 171d80803..e3f114bc6 100644 --- a/tests/testthat/test-expect-inheritance.R +++ b/tests/testthat/test-expect-inheritance.R @@ -62,6 +62,12 @@ test_that("expect_s3_class allows unquoting of first argument", { }) +test_that("expect_s4_class allows unquoting of first argument", { + cls <- methods::setClass("new_class", slots = c("a" = "numeric")) + obj <- methods::new("new_class", a = 3) + expect_success(expect_s4_class(!! rlang::quo(obj), "new_class")) +}) + # expect_s7_class -------------------------------------------------------- test_that("checks its inputs", {