Currently, assert_raise expects you to know exactly what kind of exception
is going
to be thrown by raise. Basically it tests to see if exception.class ==
expected.class.
I think a more appropriate behavior would be to test
exception.kind_of?expected. I
would also be happy if there were one method that performed the way it does
currently
and another that checks exception parentage.
Please see the code below for an example of two tests. I think both should
pass but
only the first test does because ArgumentError != StandardError.
Sean Carley
### Begin test.rb ###
require 'test/unit'
class TestRaise < Test::Unit::TestCase
def test_raise
assert_raise(ArgumentError){raise ArgumentError.new("basic argument
issue")}
end
def test_raise_parent
assert_raise(StandardError){raise ArgumentError.new("basic argument
issue")}
end
end
### End test.rb ###
ruby test.rb
Loaded suite test
Started
.F
Finished in 0.018356 seconds.
1) Failure:
test_raise_parent(TestRaise) [test.rb:7]:
<StandardError> exception expected but was
Class: <ArgumentError>
Message: <"basic argument issue">
---Backtrace---
test.rb:7:in `test_raise_parent'
test.rb:7:in `test_raise_parent'
···
---------------
2 tests, 2 assertions, 1 failures, 0 errors