Archive

Monthly Archives: August 2013

I write a lot of JavaScript these days and got quite accustomed to Jasmine-style unit tests with their expressiveness and flexibility. I also code a fair amount of Scala and one thing I miss every time I switch is a good support for BDD. I use ScalaTest and it is a powerful framework but one thing it is missing for years is the support for hierarchical specs. Namely, the analog of Jasmine’s “beforeEach” and “afterEach” in nested “describe”s. So recently, after struggling once again to express a test concisely, I felt that enough was enough. Here is a FunSpec extension trait I came up with:

When mixed in, the trait intercepts FunSpec’s “describe”s to keep track of all the “beforeEach” and “afterEach” on every nesting level. It also overrides FunSpec’s “it” to execute appropriate setup and tear-down code for that “it” before running the test. And here is a contrived example of using it in Scala:

For a complete project that you can explore or execute with maven look here: https://github.com/prystupa/jasmine-spec-scala