I have something that I am testing that I will know its working if it fails. Is there a better way to code this in ruby with test-unit than what I have in my example below?
begin
x = Method.shouldFail
assert_true(false)
rescue Test::Unit::AssertionFailedError
assert_true(false) #stop test, this is a failure
rescue => e
assert_equal(400, e.code)
end
This seems very clunky is there a better way to write this? I would expect that Method.shouldFail would always fail but it might not. And I would assume that in the last rescue block e.code should always be 400 but it could be something else.
您可以使用assert_raise
来测试是否抛出了特定异常。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.