From: Matt Armstrong Date: 2001-11-09T08:29:07+09:00 Subject: [ruby-talk:24709] Re: assert_exception_and_message Robert Feldt writes: > Hi, > > I didn't find a way in RubyUnit to check both an exception and its error > message. Maybe its there somewhere. If not here's one version: > > def assert_exception_and_message(exception, eMessage, message = "") > exception_raised = true > begin > yield > exception_raised = false > rescue Exception => e > raise e unless exception === e > assert_equals(eMessage, e.message) > end > assert(exception_raised, message) > end > > Its not perfect but can easily be fixed. If something similar is not > in Lapidary I'd propose its added to the merged Test::Unit. Is it considered good style to rely on the exception message in programs? I was always under the impression that the messages were there mainly for human consumption. Not that the above assertion would not be useful. In any case, it'd be neat if message could also be a regexp. :-) -- matt