From: John Barnette Date: 2009-09-02T16:40:37+09:00 Subject: Re: minitest assert_throws, why rescue? On Sep 2, 2009, at 12:12 AM, Intransition wrote: > In minitest why does assert_throws rescue ArgumentError/NameError ? NameError (or ArgumentError on 1.9) is what's raised by Kernel#throw when there's no catch block for the thrown symbol. ~ j. > > def assert_throws sym, msg = nil > default = "Expected #{mu_pp(sym)} to have been thrown" > caught = true > catch(sym) do > begin > yield > rescue ArgumentError => e # 1.9 exception > default += ", not #{e.message.split(/ /).last}" > rescue NameError => e # 1.8 exception > default += ", not #{e.name.inspect}" > end > caught = false > end > > assert caught, message(msg) { default } > end > > Thanks. >