Hi,

In <877i86jzzl.fsf / fsij.org>
  "[ruby-core:19374] assert_raises(mod) in minitest" on Sat, 18 Oct 2008 13:19:46 +0900,
  Tanaka Akira <akr / fsij.org> wrote:

> assert_raises(mod) in minitest fails even if the raised
> exception is a kind of mod.
> 
> But assert_raises in test/unit in ruby 1.8 succeeds.

> % svn diff --diff-cmd diff -x -u lib/minitest/unit.rb
> Index: lib/minitest/unit.rb
> ===================================================================
> --- lib/minitest/unit.rb	(revision 19827)
> +++ lib/minitest/unit.rb	(working copy)
> @@ -139,7 +139,8 @@
>          yield
>          should_raise = true
>        rescue Exception => e
> -        assert_includes(exp, e.class, exception_details(e, "<#{mu_pp(exp)}> exception expected, not"))
> +        assert_respond_to exp, :any?
> +        assert(exp.any? {|m| e.kind_of? m }, exception_details(e, "<#{mu_pp(exp)}> exception expected, not"))
>          return e
>        end
>  

This change causes other incompatible.
assert_raises(expected_exception) will pass even if the
raised exception is kind of expected exception class.

% cat /tmp/mr.rb
require 'minitest/unit'

class TestRaises < MiniTest::Unit::TestCase
  class E < StandardError
  end

  def test_raise
    assert_raises(StandardError) {
      raise E
    }
  end
end

MiniTest::Unit.autorun
% ./ruby /tmp/mr.rb
Loaded suite /tmp/mr
Started
.
Finished in 0.000550 seconds.

1 tests, 2 assertions, 0 failures, 0 errors, 0 skips
% cat /tmp/tr.rb
require 'test/unit'

class TestRaises < Test::Unit::TestCase
  class E < StandardError
  end

  def test_raise
    assert_raises(StandardError) {
      raise E
    }
  end
end
% ruby1.8 /tmp/tr.rb
Loaded suite /tmp/tr
Started
F
Finished in 0.027081 seconds.

  1) Failure:
test_raise(TestRaises) [/tmp/tr.rb:8]:
<StandardError> exception expected but was
Class: <TestRaises::E>
Message: <"TestRaises::E">
---Backtrace---
/tmp/tr.rb:9:in `test_raise'
/tmp/tr.rb:8:in `test_raise'
---------------

1 tests, 1 assertions, 1 failures, 0 errors

Index: lib/minitest/unit.rb
===================================================================
--- lib/minitest/unit.rb	(revision 19827)
+++ lib/minitest/unit.rb	(working copy)
@@ -139,7 +139,9 @@
         yield
         should_raise = true
       rescue Exception => e
-        assert_includes(exp, e.class, exception_details(e, "<#{mu_pp(exp)}> exception expected, not"))
+        assert_respond_to(exp, :any?)
+        assert(exp.any? {|ex| ex.instance_of?(Module) ? e.kind_of?(ex) : ex == e.class},
+               exception_details(e, "<#{mu_pp(exp)}> exception expected, not"))
         return e
       end
 


Thanks,
--
kou