我想使用一個斷言來引發rake任務中的錯誤。在Ruby中使用斷言的最佳實踐是什麼,但不是作爲單元測試的一部分?
the_index = items.index(some_item)
assert_not_nil the_index, "Lookup failed for the following item: " + some_item
我得到undefined method assert_not_nil
。我可以在我的rake任務中包含斷言文件嗎?怎麼樣?
這是一個最佳實踐,還是有更好的方法來做到這一點?
使用Ruby 1.9.2。
單元測試和異常處理是兩個非常不同的事情。 – 2011-12-15 03:15:13