minitest assert_throws, why rescue?

I

Intransition

In minitest why does assert_throws rescue ArgumentError/NameError ?

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.
 
J

John Barnette

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top