Behavior Driven Development: BooSpec
This weekend is watched this video I then spent a lot of time exploring a relatively new concept in the agile development world: Behavior Driven Development (BDD).
RSpec is a Ruby project to allow creation of runnable specifications. There is a related project for .NET called NSpec
I have also been exploring Boo , a cool new language targeting .NET. Whilst NSpec allows the creation of runnable specs, I don't like the slightly clunky syntax imposed by C#. I want my spec to be as human readable as possible. Basically we need extension methods in C#. These are coming in 3.0, but for now I thought I'd look at Boo. Boo allows me to more closely approximate RSpec's Ruby syntax, giving rise to Boo specs like this:
namespace Test
import BooSpec
[Context]
class EmptyStack:
private stack as Stack
[SetUp]
def SetUp():
stack = Stack(10)
[Specify]
def CountIsZero():
stack.Count.Must().Equal(0)
[Specify]
def PopThrowsException():
{ stack.Pop() }.Must().Throw(typeof(IllegalOperationException))
[Specify]
def PushedItemIsOnTop():
stack.Push(42)
stack.Peek().Must().Equal(42) I especially like "{ stack.Pop() }.Must().Throw(typeof(IllegalOperationException))". It's just so succinct!
I'm tempted to start a new project called "BooSpec". This would be a library similar to RSpec and NSpec, but written in Boo. The BooSpec library could be used by any .NET language, except the Must() extension methods calls would have to revert to normal static calls. Of course there is nothing wrong with writing the spec in Boo and the application code in C# or VB.NET!

Loading…
Add a comment
You are not allowed to comment on this entry as it has restricted commenting permissions.