From: James Gray Date: 2009-05-25T12:04:12+09:00 Subject: Re: Test::Unit : assert_aborts On May 24, 2009, at 6:17 PM, Stephan Wehner wrote: > You mean something like this. > > > require "test/unit" > require 'stringio' > > class TestErrorHandling < Test::Unit::TestCase > def test_error_type_and_message_II > assert_aborts(/bye/i) do > abort "Bye." > end > end > > private > > def assert_aborts(pattern) > save_stderr = $stderr > begin > $stderr = StringIO.new > e = assert_raise(SystemExit) do > yield if block_given? > end > assert_match pattern, e.message > ensure > $stderr=save_stderr > end > end > end > > __END__ Sort of like that, yeah. Basically what I was saying is that I feel an assert_aborts() method tests an implementation detail. It doesn't really matter if I use abort() or some output method and then call exit() myself. There may be good reasons to do that too, say if you are printing a complex error message and using printf() would make it easier to format. We really just want to know if the user saw an error and if the program is quitting, so it's better to test for that. James Edward Gray II