I'm using Specs2 to write a specification for a measurement library. To verify the calculated measures I have numerous source files covering standard cases as well as a lot of corner cases. I did analyze them manually to I know the exact measures, but to document everything and automate it, this should be part of a Specs2 specification.
So far I copied some of the source files into my specification and passed it to the verifying methods as string. However, this has the downside, that the inlined code isn't checked anymore - the external files are verified by the standard compiler so I'm sure it is valid code. It's no problem to just pass the filename, but my specification should include the source code in the resulting HTML report and not only point to a file one has to dig out and look at manually. To give you some idea here is the code I'm using right now
class CountVisitorSpec extends Specification { def is =
"Given the ${com/example/Test1.java} source, the visitor should deliver a count of ${16}" ! new GivenThen {
def extract(text: String) = {
val (filename, count) = extract2(text)
val file = classOf[CountVisitorSpec].getClassLoader.getResource(filename).getFile
val src = Path(file).slurpString
val visitor = new CountVisitor
AstAnalyzer.runWith(src, visitor)
visitor.count must_== count.toLong
}
}
}
Does someone have an idea, how it is possible to point to the external files so that they are included as initial input in the resulting HTML report?