Rails Minitest:使用 assert_predicate 时 "false is not a symbol or a string"

Rails Minitest: "false is not a symbol or a string" when using assert_predicate

在使用 Minitest 的 rails 单元测试中,使用以下代码:

def test_notification
  # ("Arrange" stuff here...)

  get root_path

  assert_predicate flash, blank?
end

当运行时,assert_predicate行导致错误:

Minitest::UnexpectedError: TypeError: false is not a symbol nor a string

这是怎么回事?

问题是 blank? 需要是一个符号——它在上面的代码片段中缺少前导 :。更正后的代码:

def test_notification
  # ("Arrange" stuff here...)

  get root_path

  assert_predicate flash, :blank?
end