Created
April 3, 2013 00:28
-
-
Save carey/5297461 to your computer and use it in GitHub Desktop.
Assert that a code block throws an exception or a subclass in Scala.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def assertThrows[A <: Throwable: ClassTag](fn: => Unit) { | |
val ct = classTag[A] | |
try { | |
fn | |
fail("Expected " + ct) | |
} catch { | |
case ct(e: Throwable) => // ok | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment