I am new to Spec2, and trying to learn it. I come up with the following codes,
@RunWith(classOf[JUnitRunner])
class GWTStyleSpec extends Specification {
"A given-when-then example for the addition" ^
"Given the following number: ${1}" ^ number1 ^
"And a second number: ${2}" ^ number2 ^
"Then I should get: ${3}" ^ result ^
end
val number1: Given[Int] = (_: String).toInt
val number2: When[Int, (Int, Int)] = (n1: Int) => (s: String) => (n1, s.toInt)
val result: Then[(Int, Int)] = (n: (Int, Int)) => (s: String) => ((n._1 + n._2) must_== s.toInt)
}
After run it, I got java.lang.Exception: Could not instantiate class com.me.scala.start.GWTStyleSpec: null and with lots of exception stack trace below it.
What did I do wrong for this?
If you are importing
org.specs2.Specification
then there should be adef is = ...
method defined:It is also possible that the
val
s are not being instantiated properly so you can try usinglazy val
s.Note also that the next specs2 version (1.15-SNAPSHOT) proposes another style of Given/When/Then specifications based on Scala 2.10 features: