Scala with Instinct
I was lucky enough to spend that last half of last week in a Scala course run by Tony Morris (contact us at Workingmouse if you’re interested in Scala or the course).
The Scala syntax is very malleable and lends itself well to expressing DSLs. With this in mind, here’s a simple Instinct specification written in Scala (it doesn’t work yet, though I think this is an IDE issue, rather than a limitation)
import com.googlecode.instinct.marker.annotate.Specification
import com.googlecode.instinct.integrate.junit4.InstinctRunner
import org.junit.runner.RunWith
@RunWith(classOf[InstinctRunner])
class AnEmptyStack {
@Specification
def isEmpty = {}
}
Once we get the next release out, I’d like to spend some time playing around with using Scala to spec Java objects, there should be no reason it can’t also be used to spec out Scala code also (there may be some other things we need to do).
Here’s some RSpec like (valid) Scala:
describe "An empty stack" = {
it "is empty" = {}
}
G’day Tom,
Consider losing the braces in your second code sample:
describe “An empty stack” = it “is empty” {}
Also, remember to try not to use = when you have a side-effecting function, so the first code example:
def isEmpty{}
There is similar code to this in ScalaCheck to “test itself” that you might be interested in. You also might consider looking at Specs.
Tony Morris
15 Jan 08 at 6:45 am