Method: MiniTest::Assertions#assert_throws

Defined in:
lib/minitest/unit.rb

#assert_throws(sym, msg = nil) ⇒ Object

Fails unless the block throws sym



436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
# File 'lib/minitest/unit.rb', line 436

def assert_throws sym, msg = nil
  default = "Expected #{mu_pp(sym)} to have been thrown"
  caught = true
  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
      default += ", not #{e.message.split(/ /).last}"
    rescue NameError => e         # 1.8 exception
      default += ", not #{e.name.inspect}"
    end
    caught = false
  end

  assert caught, message(msg) { default }
end