Can't expect error from assertthat with testthat
I made the following test in tests/test-Leslie.R
test_that("Expected errors with Leslie", {
# wrong birth_rate
expect_error(
Leslie(birth_rate = c(0.5,0.4), phi = phi, maturity = maturity),
"birth_rate is not a number (a length one numeric vector)."
)
})
it gives :
Testing RLA
√ | OK F W S | Context
x | 2 1 | Leslie output compliance
--------------------------------------------------------------------------------
test-Leslie.R:23: failure: Expected errors with Leslie
`Leslie(birth_rate = c(0.5, 0.4), phi = phi, maturity = maturity)` threw an error with unexpected message.
Expected match: "birth_rate is not a number (a length one numeric vector)."
Actual message: "birth_rate is not a number (a length one numeric vector)."
Backtrace:
1. testthat::expect_error(...) C:\Users\mgenu.RATUFA\Documents\Projet\package\RLA/tests/testthat/test-Leslie.R:23:2
6. RLA::Leslie(birth_rate = c(0.5, 0.4), phi = phi, maturity = maturity)
7. assertthat::assert_that(...) R/Leslie.R:32:2
--------------------------------------------------------------------------------
√ | 1 | MNPL
√ | 1 | bycatch_obs
√ | 1 | bycatch_rw
√ | 1 | forward_pbr
√ | 1 | get_streaks
√ | 1 | inverse_MNPL
√ | 1 | inverse_lambda_leslie
√ | 1 | lambda
√ | 1 | pbr_nouveau
√ | 1 | pellatomlinson_pbr
√ | 1 | rlafit
√ | 1 | stableage
√ | 1 | standata
√ | 1 | time2CO
== Results =====================================================================
Duration: 0.1 s
OK: 16
Failed: 1
Warnings: 0
Skipped: 0
Don't worry, you'll get it.
expected match and actual message are the same but R doesn't recognize them as equal...