diff options
| author | gotoyuzo <gotoyuzo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-12-28 19:47:55 +0000 |
|---|---|---|
| committer | gotoyuzo <gotoyuzo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-12-28 19:47:55 +0000 |
| commit | 0039430d54bebf41e2cd0e71f8c03a4560026110 (patch) | |
| tree | d1c884bec5e5685b0326664574e8191311000728 /lib/test/unit | |
| parent | 3e4eee53f679f0f2f878a9b58e8d7ba2630f3acd (diff) | |
| download | ruby-0039430d54bebf41e2cd0e71f8c03a4560026110.tar.gz ruby-0039430d54bebf41e2cd0e71f8c03a4560026110.tar.xz ruby-0039430d54bebf41e2cd0e71f8c03a4560026110.zip | |
* lib/test/unit/assertions.rb (Test::Unit::Assertions#assert_throws):
throw won't raise NameError nor ThreadError but ArgumentError on 1.9.
(Test::Unit::Assertions#assert_not_throws): ditto.
* test/testunit/test_assertions.rb: add assertions for throwing some
objects other than Symbol.
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@14777 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/test/unit')
| -rw-r--r-- | lib/test/unit/assertions.rb | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/lib/test/unit/assertions.rb b/lib/test/unit/assertions.rb index 0d55b0b06..7c2c721fc 100644 --- a/lib/test/unit/assertions.rb +++ b/lib/test/unit/assertions.rb @@ -369,11 +369,12 @@ EOT end end - UncaughtThrow = {NameError => /^uncaught throw \`(.+)\'$/, - ThreadError => /^uncaught throw \`(.+)\' in thread /} #` + UncaughtThrow = { + ArgumentError => /^uncaught throw (.+)$/, + } #` ## - # Passes if the block throws +expected_symbol+ + # Passes if the block throws +expected_value+ # # Example: # assert_throws :done do @@ -381,23 +382,22 @@ EOT # end public - def assert_throws(expected_symbol, message="", &proc) + def assert_throws(expected_value, message="", &proc) _wrap_assertion do - assert_instance_of(Symbol, expected_symbol, "assert_throws expects the symbol that should be thrown for its first argument") assert_block("Should have passed a block to assert_throws."){block_given?} caught = true begin - catch(expected_symbol) do + catch(expected_value) do proc.call caught = false end - full_message = build_message(message, "<?> should have been thrown.", expected_symbol) + full_message = build_message(message, "<?> should have been thrown.", expected_value) assert_block(full_message){caught} - rescue NameError, ThreadError => error + rescue ArgumentError => error if UncaughtThrow[error.class] !~ error.message raise error end - full_message = build_message(message, "<?> expected to be thrown but\n<?> was thrown.", expected_symbol, $1.intern) + full_message = build_message(message, "<?> expected to be thrown but\n<#$1> was thrown.", expected_value) flunk(full_message) end end @@ -417,11 +417,11 @@ EOT assert(block_given?, "Should have passed a block to assert_nothing_thrown") begin proc.call - rescue NameError, ThreadError => error + rescue ArgumentError => error if UncaughtThrow[error.class] !~ error.message raise error end - full_message = build_message(message, "<?> was thrown when nothing was expected", $1.intern) + full_message = build_message(message, "<#$1> was thrown when nothing was expected") flunk(full_message) end assert(true, "Expected nothing to be thrown") |
