Method: MiniTest::Assertions#assert_throws
- Defined in:
- lib/minitest/unit.rb
#assert_throws(sym, msg = nil) ⇒ Object
Fails unless the block throws sym
297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 |
# File 'lib/minitest/unit.rb', line 297 def assert_throws sym, msg = nil default = "Expected #{mu_pp(sym)} to have been thrown" caught = true catch(sym) do begin yield rescue ArgumentError => e # 1.9 exception default += ", not #{e..split(/ /).last}" rescue NameError => e # 1.8 exception default += ", not #{e.name.inspect}" end caught = false end assert caught, (msg) { default } end |