Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This seems odd behaviour.</p> <p>From: <a href="http://bfts.rubyforge.org/minitest/MiniTest/Assertions.html#method-i-assert_raises" rel="nofollow">http://bfts.rubyforge.org/minitest/MiniTest/Assertions.html#method-i-assert_raises</a></p> <pre><code># File lib/minitest/unit.rb, line 337 def assert_raises *exp msg = "#{exp.pop}\n" if String === exp.last should_raise = false begin yield should_raise = true rescue MiniTest::Skip =&gt; e details = "#{msg}#{mu_pp(exp)} exception expected, not" if exp.include? MiniTest::Skip then return e else raise e end rescue Exception =&gt; e details = "#{msg}#{mu_pp(exp)} exception expected, not" assert(exp.any? { |ex| ex.instance_of?(Module) ? e.kind_of?(ex) : ex == e.class }, exception_details(e, details)) return e end exp = exp.first if exp.size == 1 flunk "#{msg}#{mu_pp(exp)} expected but nothing was raised." if should_raise end </code></pre> <p>This checks the exception passed is an instance of <code>Module</code> and if so uses <code>e.kind_of?(ex)</code> which would work fine as as instance of <code>SomeException</code> will be of kind <code>Exception</code> BUT only if <code>ex</code> is a Module, so <code>Exception</code> won't work. It needs to be something common that you have mixed into your exceptions. </p> <p>(As shown here <a href="http://ruby-doc.org/core-2.0/Object.html#method-i-kind_of-3F" rel="nofollow">http://ruby-doc.org/core-2.0/Object.html#method-i-kind_of-3F</a>)</p> <p>This matches minitests own tests ... </p> <pre><code> module MyModule; end class AnError &lt; StandardError; include MyModule; end .... def test_assert_raises @tc.assert_raises RuntimeError do raise "blah" end end def test_assert_raises_module @tc.assert_raises MyModule do raise AnError end end </code></pre> <p>(From: <a href="https://github.com/seattlerb/minitest/blob/master/test/minitest/test_minitest_unit.rb" rel="nofollow">https://github.com/seattlerb/minitest/blob/master/test/minitest/test_minitest_unit.rb</a> )</p> <p>So.. if your Exception mixes in a module, you can assert on the module.. but other than that go with @vgoff's answer.. or extend minitest to do what you want.</p> <p>Note: I love that ruby is all open source!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload