Method: Minitest::Assertions#assert_throws
- Defined in:
- lib/minitest/assertions.rb
#assert_throws(sym, msg = nil) ⇒ Object
Fails unless the block throws sym
475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 |
# File 'lib/minitest/assertions.rb', line 475 def assert_throws sym, msg = nil default = "Expected #{mu_pp(sym)} to have been thrown" caught = true value = catch(sym) do begin yield rescue ThreadError => e # wtf?!? 1.8 + threads == suck default += ", not \:#{e.message[/uncaught throw \`(\w+?)\'/, 1]}" rescue ArgumentError => e # 1.9 exception raise e unless e..include?("uncaught throw") default += ", not #{e.message.split(/ /).last}" rescue NameError => e # 1.8 exception raise e unless e.name == sym default += ", not #{e.name.inspect}" end caught = false end assert caught, (msg) { default } value rescue Assertion raise rescue => e raise UnexpectedError, e end |