Archive for the 'Geekery' Category


StorEvil 0.1 released

StorEvil 0.1 was “released” today… and by “released” I mean I zipped up the binaries and added some installation instructions.

You can get it from the github download page.

Changes since my last in-depth post about StorEvil:

– Added HTML reporting of spec results using the Spark View Engine.
– New command “storevil init” which creates a config file & spark template in the current directory as well as some examples.
– Ability to bind tables to arrays of parameters that are custom types. (more info on the github wiki).
– Added an example that implements Conway’s Game Of Life using the Cucumber features created by Corey Haines.
– Hacked out a very early semi-functional ReSharper runner (not included in the binaries yet… only supports ReSharper 5 Beta). I’ll work on this more once ReSharper 5.0 is released.
– Support for dependent contexts: StorEvil will inject any constructor parameters into your context classes, and reuse the same contexts throughout the execution of a scenario (so you can break up your contexts into classes irrespective of their shared context). (more info on the github wiki)
– Cleaned up some namespace inconsistencies
– Reworked and simplified a bunch of complex code (Thank you Reflector & the CodeMetrics plugin)
– fixed a bunch of bugs (of course)

If you take a look at it let me know what you think.


StorEvil: What’s in a Name?

My Alt.NET Seattle compatriot Brian Henderson asked about the reason behind the name “StorEvil”.

It’s sort of a pun… first off, obviously, in agile development, a unit of work to-be-done is often referred to as “story”. In StorEvil, “Story” refers to a set of scenarios (basically a single natural language specification file).

Also, many years ago, when I was young and just getting into jazz, I listened to a certain live Charlie Parker album quite a bit.

Also, I’ve always had the suspicion that the whole idea of natural language specs might be slightly Evil.

So, being an old DOS/Windows guy, I just took “Storyville” and twisted it into an 8-character name that almost makes sense.

So there you have it, the triple-entendre behind the StorEvil name.


Introduction to StorEvil


This is the first in a series of posts about a tool I wrote a while back, and have recently picked up again, called StorEvil.

You can check out StorEvil on GitHub

After I wrote it I sort of lost interest in this whole approach, although I paid some attention to Cucumber as it gained popularity.
Recently, at an Alt.NET Seattle meeting, I saw a demo of SpecFlow, which is a similar tool for .NET.

SpecFlow is a nice tool insofar as it is basically a reimplementation of Cucumber in .NET.
However, I think that some of the nice metadata tools (Reflection) that we have in .NET can provide for a much richer experience.
This is not to imply that I think .NET is better than Ruby for this type of thing, by any means. In fact, quite the opposite.

But, if you are going to take on the pain of static-typing, I think you should partake of the joy of System.Reflection to provide a tool that does things that are simply not possible or very difficult in Ruby.
Otherwise, you might as well just use Cucumber and IronRuby… Or eschew .NET altogether if possible.

Now, big disclaimer: StorEvil is not very polished. It may not work on your machine. It may not work as expected.
I’m pretty sure that it won’t reformat your hard disk, but beyond that I make no claims.

What is StorEvil?

Well, if you know what Cucumber is, you can basically think of it as a Cucumber-ish tool for .NET that allows you to easily write .NET code to interpret natural language specifications.
If you don’t know what Cucumber is, I would advise you to read about it.

StorEvil is a tool that you can use to write specifications in English, and then execute those specifications.
It supports a set of natural language that is a subset of the Gherkin language used by Cucumber.

It supports .NET languages such as C#.
It has only been tested on Windows (so far).
It only supports English (so far).

Why StorEvil?

Reflection-based language matching

Other similar tools use regular expressions, which makes sense for Ruby.

In .NET, there is a rich Reflection model which gives access to the method names, parameter names and type info,
which can help to reduce noise and code-duplication.

In StorEvil, although Regular-Expression matching is supported, matching based on the names of functions is the preferred method:

For example, in order to match the following:

Given I have a savings account with $100

In SpecFlow, and similarly in Cucumber (ignoring the language differences between C# & Ruby), you would write something like this:

[Given(@"I have a (\w+) account with $(.*)")]
public void GivenIHaveAccount(string type, decimal amount) { ... }

In StorEvil, you could use similar syntax to the above, OR, you can write it in as follows:

public void Given_I_Have_A_accountType_Account_with_amount(string accountType, decimal amount) { ... }

StorEvil splits the method name into its constituent words and matches the values to the parameters based on the names of the parameters (accountType and amount).

Context Chaining

In StorEvil, your Context class methods (like Steps in Cucumber) can return any object, which can then be used to fulfill the remaining grammar on a line.

For example, in the specification alluded to in the above example, you may end up with the following similar steps:

Given I have a savings account with a balance of $100
Given I have a savings account that is preferred
Given I have a checking account that has been placed on fraud alert

In StorEvil, rather than creating a separate step for each one of these, you could do the following:

public class AccountTestContext {
    public AccountOptions Given_I_Have_A_accountType_Account(string accountType) { 
        // create and return AccountOptions object here     

public class AccountOptions {
    public void With_a_balance_of_accountBalance(decimal accountBalance) { ... }
    public void That_is_preferred() { ... }
    public void That_has_been_placed_on_fraud_alert() { ... }

StorEvil will first invoke AccountTestContext.GivenIHaveAaccountType_Account(), passing in the account type.
It will then take the returned AccountOptions object and invoke the appropriate method to complete the rest of the step.

You could also declare a method to return object or any other type, and return different types of objects from the function depending on the parameters.

This can be chained to as deep a level as desired.

On successive steps during a scenario, StorEvil will preserve the same context objects…
meaning that you can use private variables in the context objects to maintain state between steps.

Extension Method Support

StorEvil can invoke extension methods. For example, to interpret the following:

My total balance should equal $42

You could write something like this:

public static class TestExtensionMethods
    public static void ShouldEqual(this object actual, object expected)
       ... assertion code here ...

public class AccountTestContext {

    public decimal My_Total_Balance { get { return ... ;}} 

StorEvil will invoke the .ShouldEqual() extension method on the number returned by AccountTestContext.MyTotalBalance property, passing in “$42”;

Executes in the console

StorEvil is executed via a simple command-line interface. This is my personal preference. It might not be for you if you are not comfortable on the command-line. Integration with ReSharper is something I’ve looked into but frankly, it’s kind of a bear and not high on the priority list right now.

It was originally written to generate NUnit fixtures (and still supports this), although there are some limitations to the NUnit fixture generation.

Why not StorEvil?

Less polished than other options

StorEvil does not have VisualStudio integration.

StorEvil does not have NAnt or MSBuild tasks. (yet)

It does not have TDD.NET or Resharper integration.
(Unless you use it in NUnit generation mode)

Update: I have built an alpha ReSharper runner (5.0 only)

Overall, it just a less-used tool than the other options.

Is natural language testing appropriate?

There is definitely an extra cost to writing natural language specs as well as context classes.
Sometimes it can even feels like “writing the tests twice”.

Another option is to use a tool whose output is close to the natural language specification.
For .NET development, Machine.Specifications (MSpec) is a good choice.

Other similar tools


Cucumber is by far the most established BDD tool, and if you use Ruby you have probably heard of it.
It is in use by a large number of people, supports many languages, and is under very active development.


SpecFlow is another .NET tool that is similar to Cucumber. It also has a fairly active community.


Calculator TDD Kata in JavaScript

So, I’m back from the deadosphere.

Here’s a run through  Roy Osherove’s Calculator Kata, in JavaScript, using Screw.Unit.

It was quite educational to do this kata and watch it back on video. The main things I learned were:

I am a horrible typist.

Writing code takes a lot longer than I think it does.

I expected to be able to do the beginner steps in about 10 minutes, but it actually took more than twice that long. Some of this is down to unfamiliarity with the editor (RubyMine), and some of it is standard programmer optimism.

It is embarrassing to watch yourself code….

I did this kata three times so I’ve watched myself code more than is healthy.

… but it is a great learning experience as well.

I see a lot of areas I can improve on, coding-wise, and there are some things I do a lot that I’ve never noticed before.

Without further ado…

Here it is. The first 21 minutes are the “beginner” steps, the following steps are about 15 minutes, and the remaining few minutes are code tidying. There is sporadic commentary for the bits that I feel are noteworthy.


Visual Studio 2005 and Monorail RC3 setup for local development on Vista/IIS 7

These are the steps I had to follow to get my Monorail RC3 project up and running in Visual Studio 2005 on Vista on my MacBook.

1. Install IIS6 compatibility, Metabase, and Application Development Features from Control Panel\Programs and Features\Turn Windows Features On and Off.


2. Follow the instructions here: How to map .rails to the runtime on IIS7.

3. If you are using <httpModules> in web.config, change the application pool to the Classic Application Pool (in IISManagementConsole, click the Advanced Settings… link on the right side). Alternatively, follow the instructions to migrate to the integrated pipeline mode (I couldn’t for this project).


SQL Server Change Management: The Low-Tech Approach

Dealing with database changes can really be a pain in the ass. Here’s one exceedingly low-tech solution that I am using.

On my current project (SQL Server, using SQLExpress for local development), we store a backup from the live database in a zip file in SVN. We store an actual live backup, but for another project I might scrub most of the data, depending on the size of the database and the nature of the personal info involved.

We name our SQL scripts for a particular release so that when sorted by file name, they execute in the correct order:



Note that on SQL Server (and probably other RDBMSes as well), many scripts are order-independent (sprocs). Even so, many times it is easiest to deal with the migration as a series of deltas that execute in order.

We also store an SQL file that creates an empty database and user. I generated this by using SQL Management Studio to script my changes, and then deleting the cruft from the resultant script, so that it can run on SQL2005 and SQL2000.

We have a batch file like the following that any developer can run that will create a clean local copy of the database with all scripts applied.

This also is used to verify that script changes/additions are working before commiting to SVN.

It’s pretty low-tech but it works so far.

REM pass in the server name (for ex localhost\SQLEXPRESS)

REM unzip .bak backup from zip file

7za e -y

REM script that creates empty database, user, etc.

REM this SQL file can be created by hand or from Management Studio

type Create_Local_DB_And_Restore_From_live_Backup.sql >> tmp.sql

REM create monster script by concatenating in order of file name

REM we name them 000_foo.sql, 001_bar.sql etc

for /f %%G in (‘dir /b /o:n Path\To\Scripts\*.sql’) do type Path\To\Scripts\%%G >> tmp.sql

REM execute the monster script (uses windows auth)

osql -S %1 -d master -E -i tmp.sql

REM so we can examine tmp.sql if anything went wrong


del Live_Database_Backup.bak

del tmp.sql