Skip to content

Commit

Permalink
allow unquoting first arg for expect_s4_class
Browse files Browse the repository at this point in the history
  • Loading branch information
stibu81 committed Mar 2, 2025
1 parent 30f5b11 commit ae4e39c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 2 additions & 2 deletions R/expect-inheritance.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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 {
Expand Down
6 changes: 6 additions & 0 deletions tests/testthat/test-expect-inheritance.R
Original file line number Diff line number Diff line change
Expand Up @@ -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", {
Expand Down

0 comments on commit ae4e39c

Please sign in to comment.