Jasmine-style BDD tests in Scala


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

Advertisements
1 comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: