nosewheelie

Technology, mountain biking, politics & music.

Scala with Instinct

with one comment

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" = {}
}

Written by Tom Adams

January 14th, 2008 at 11:27 am

Posted in Instinct, Java, Scala, TDD

One Response to 'Scala with Instinct'

Subscribe to comments with RSS or TrackBack to 'Scala with Instinct'.

  1. 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

Leave a Reply