On May 24, 2009, at 4:44 AM, Stephan Wehner wrote:

> Brian Candler wrote:
>> Have you tried
>>
>>    assert_raises(AbortException) { ... }
>>
>> ?
>
> Thanks -- if you are suggesting to leave out the method  
> assert_aborts: I
> thought it might be good to check the abort message. Otherwise, please
> let me know.

It's possible to check the message even in old versions of  
Test::Unit.  For example:

class SpecificError < RuntimeError; end

require "test/unit"

class TestErrorHandling < Test::Unit::TestCase
   def test_error_type_and_message
     error = assert_raise(SpecificError) do
       raise SpecificError, "Magic message goes here..."
     end
     assert_match(/magic/i, error.message)
   end
end

__END__

As for testing for abort(), I wouldn't.  What are you really trying to  
figure out, if the code would exit with an error message?  Then check  
that.  Throw a StringIO in $stderr and check for a message and see if  
Ruby is planning to exit.  abort() raises the same Exception exit  
does, so just check for that:

require "test/unit"

class TestErrorHandling < Test::Unit::TestCase
   def test_error_type_and_message
     assert_raise(SystemExit) do
       abort "Bye."
     end
   end
end

__END__

Hope that helps.

James Edward Gray II