Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# testthat (development version)

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

Expand Down
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
Loading