Jan 27 2006

Developments in Spec-land

admin @ 1:53 am

Over the past week or so I’ve been experimenting with Ambrai Smalltalk: a native OS X Smalltalk.

I’ve tweaked up the sUnit that comes with it and am in the process of porting rSpec to Smalltalk. Pretty much all that’s left to do is a runner.

Dave Chelimsky has been doing some interesting experiments with using a helper class for implementing expectations. More on that later.

Also, Nancy and I have been working on a native Cocoa runner for rSpec on OS X.

Tags: 

Jan 13 2006

iLife & iWork

admin @ 2:30 am

The local Apple Store got their first shipment of the new iLife & iWork today. I called and had them set a copy of each side to make sure I got them. I’m looking forward to exploring the apps over the next week or so.. but I’m quite excited after seeing the MacWorld keynote.

I’ve spent this evening using Keynote to work on slides for SD West. It’s a joy. As I’ve gotten used to since getting my first iBook almost year ago.. it just works.

Tags: 

Jan 12 2006

Singletons and FitNesse

admin @ 5:02 pm

FitNesse uses a single VM to run all pages in a test suite. This causes issues with static variables. They should be reset after each test page.

There are also issues with singletons. They, too, should be reset after each test page has run. So… you have to hunt down and reset each and every singleton in the system. As I was thinking about this, an approach occurred to me that will help with this, as well as making your singletons visible and easily findable.

Marking Singletons

I’ll start by making an interface to mark singletons:

public interface Singleton
{
}

Now I can mark each singeton, for example:

public class PrintQueue implements Singleton
{
    private static PrintQueue instance = null;

    public static PrintQueue getInstance () {
        if (instance == null) {
            instance = new PrintQueue();
        }
        return instance;
    }

    private PrintQueue() {
        //....
    }
}

So that makes the singletons easy to find.. just pull up implementors of Singleton.

Managing Singletons

Next I want to actively manage them. I’ll need to keep track of them:

public class SingletonManager
{
    private static List singletons = new ArrayList();

    public static void registerSingleton (Singleton aSingleton) {
        if (singletons.contains(aSingleton)) return;
        singletons.add(aSingleton);
    }
}

And I need to hook our singletons into the manager:

public class PrintQueue implements Singleton
{
    public static getInstance () {
        if (instance == null) {
            instance = new PrintQueue();
            SingletonManager.registerSingleton(instance);
        }
        return instance;
    }
}

Now I have a lists of all the singletons in the system. This lets me do interesting things.

Resetting Singletons

The first thing (maybe the only thing… and it’s enough… it’s the whole reason for this article) is to reset all the singletons.

public class SingletonManager
{
    public static void reset () {
        Iterator singetonIt = singetons.iterator();
        while (singletonIt.hasNext()) {
            Singleton aSingleton = (Singleton)singletonIt.next();
            aSingleton.reset();
        }
    }
}

Singleton needs a reset method now:

public interface Singleton
{
    void reset();
}

which needs to be implemented:

public class PrintQueue implements Singleton
{
    public void reset() {
        // do anything required to cleanup
        instance = null;
    }
}

Cleaning Up

Now I can use this reset facility from a fixture on the TearDown page on my test suites to reset all my singletons after each test page.

Of course, a better approach would be to not use singletons.

Tags: 

Jan 04 2006

New Digs

admin @ 12:29 am

We moved into a new home over the holidays. There’s an album of pics in the gallery section of my site.

Other than it being a kick-ass house, in general, there are two high points:

  • 550 sq.ft. of office space, and
  • a large room we’re using as an art/craft studio where I’ll have space to work on calligraphy and wargaming (Lord of The Rings and Warhammer where I play a Bretonnian army).

Below the office is basement that gives us lots of room to have gaming tables. So we’re all reinvigorated about the gaming. Expect more activity on our gaming site in the future.

Tags: No Tags