Test and exceptions

Hi

In the file testcase.rb that is part of the Test module why are only the
AssertionFailedError, StandardError and ScriptError exceptions caught?

Shouldn't snippet one (see below) be changed to snippet two (see below)?

Thanks

Snippet One:

begin
  setup
  __send__(@method_name)
rescue AssertionFailedError => e
  add_failure(e.message, e.backtrace)
rescue StandardError, ScriptError
  add_error($!)
ensure
  begin
    teardown
  rescue AssertionFailedError => e
    add_failure(e.message, e.backtrace)
  rescue StandardError, ScriptError
    add_error($!)
  end
end

Snippet Two:

begin
  setup
  __send__(@method_name)
rescue AssertionFailedError => e
  add_failure(e.message, e.backtrace)
rescue Object
  add_error($!)
ensure
  begin
    teardown
  rescue AssertionFailedError => e
    add_failure(e.message, e.backtrace)
  rescue Object
    add_error($!)
  end
end

Here's the run method that is part of the testcase class ....

def run(result)
yield(STARTED, name)
@_result = result
begin
  setup
  __send__(@method_name)
rescue AssertionFailedError => e
  add_failure(e.message, e.backtrace)
rescue Object #StandardError, ScriptError
  add_error($!)
ensure
  begin
    teardown
  rescue AssertionFailedError => e
    add_failure(e.message, e.backtrace)
  rescue Object #StandardError, ScriptError
    add_error($!)
  end
end
result.add_run
yield(FINISHED, name)
end

This was discussed on ruby-core, topic "test/unit doesn't rescue a
Exception", but it seems it's not commited yet.

Good point anyway :wink:

···

On 9/8/06, brian.kejser@protexis.com <brian.kejser@protexis.com> wrote:

Hi

In the file testcase.rb that is part of the Test module why are only the
AssertionFailedError, StandardError and ScriptError exceptions caught?

Shouldn't snippet one (see below) be changed to snippet two (see below)?