Scala – Exception matcher in Specs BDD library for Scala

bddscalaspecs

Im using the Specs BDD library for writing Scala unit tests (http://code.google.com/p/specs)
.In my code if i want to assert that a throws an exception of type ClassNotFoundException, then i can write the following code:

a must throwA[ClassNotFoundException]

However,i want to test the reverse case,i.e.i want to assert that a "does not" throw an exception of type ClassNotFoundException.

I tried using not negation matcher, as follows:

 a must throwA[ClassNotFoundException].not

But that didnt work. Im getting compilation errors. So, is there any way i can assert that an exception of type ClassNotFoundException for example, is not thrown ?

Please Help
Thank You

Best Answer

Yes there is a parsing issue when compiling:

 a must throwA[ClassNotFoundException].not

You need to write instead:

 a must not(throwA[ClassNotFoundException])
Related Topic