From: Pat Eyler Date: 2001-03-17T18:30:07+09:00 Subject: [ruby-talk:12763] Re: assert_exception question On Sat, 17 Mar 2001, Kenichi Komiya wrote: > > From: Pat Eyler > > I've got a method which should raise an exception, and I want to test it > > using runit. Only I'm not understanding the assert_exception. From Hugh > > Sasse's Docs, I read that the syntax should be: > > > > assert_exception(exception, message="") {block} > > > > This doesn't seem to be right though. What am I missing? > > The message argument is the message displayed when the assertion > is failed (just like the message argument of assert_equal). > > err = assert_exception(RuntimeError, "test01 failed") do > raise("my exception"); > end > assert_equal "my exception", err.to_s > Thanks for the answer, but things still don't seem to work the way I would expect, the following fails (at least for me): ------------------------------------------------- require 'runit/testcase' require 'runit/testsuite' class RaiseException def initialize(aString) raise aString end end class TestExcept < RUNIT::TestCase def testExcept err = assert_exception("RunTimeError","test failed") do RaiseExeption.new("this is an exception") end assert_equals("this is an exception",err.to_s) end end if $0 == __FILE__ require 'runit/cui/testrunner' RUNIT::CUI::TestRunner.run(TestExcept.suite) end ------------------------------------------------- The failure message is: ------------------------------------------------- [pate@cherry ruby]$ ./testExcept.rb TestExcept#testExcept E. Time: 0.002723 FAILURES!!! Test Results: Run: 1/1(1 asserts) Failures: 0 Errors: 1 Errors: 1 ./testExcept.rb:15:in `testExcept': class or module required (TypeError) from ./testExcept.rb:23 [pate@cherry ruby]$ ------------------------------------------------- Obviously, I'm not understanding things here. Any ideas? Other than that I'm an idiot. ;) thanks, -pate > Regards, > Komiya. >