Ruby Can";断言;为通过的断言生成输出?
Ruby Can";断言;为通过的断言生成输出?,ruby,minitest,Ruby,Minitest,assert(false,“statement is true”)生成包含描述性消息“statement is true”的输出(默认情况下,输出到stdout)。如果我希望输出也包含传递的断言的描述性消息,即如果我改为使用assert(true,“statement is true”),有没有一种简单的方法让它发送给stdout类似于“asserting'statement is true'…OK”的内容呢?当然,只要尝试一下: def assert_if(condition, message
assert(false,“statement is true”)
生成包含描述性消息“statement is true”的输出(默认情况下,输出到stdout)。如果我希望输出也包含传递的断言的描述性消息,即如果我改为使用assert(true,“statement is true”)
,有没有一种简单的方法让它发送给stdout类似于“asserting'statement is true'…OK”的内容呢?当然,只要尝试一下:
def assert_if(condition, message)
assert(!condition, message)
end
现在:
assert_if true, "statement is true"
您必须手动打印消息,您可以定义自己的断言或助手方法。 尝试: 以及: 为什么不呢?
def assert_with_message(condition, message)
assert condition
puts message
end
assert_with_message true, "Assertion success message"