I had stated in a
previous post about
the advantageous of Behavior Driven Development with Ruby and RSpec. Here I am looking
at
NSpec, an open source tool from
Tigris.
The assemblies to pull down and reference are the NSpec.Console and NSpec.Framework assemblies. There are other assemblies that check the
specifications of the Console and Framework in addition to example specifications.
For example, here is an example spec that I threw together where the TextObject class's behavior is being specified.
using System;
using System.Collections.Generic;
using System.Text;
using NSpec.Framework;
namespace NSpecTest
{
[Context]
public class HowBDDShouldBeDone
{
private TestObject testObject = new TestObject();
[Specification]
public void BehaviorDrivenDevelopmentDescribesBehaviorInSpecs()
{
Specify.That(testObject.IsFalse()).ShouldBeFalse();
}
[Specification]
public void SpecsAreUnderstoodByBusinessLine()
{
Specify.That(testObject.IsTrue()).ShouldBeTrue();
}
}
public class TestObject
{
public bool IsFalse()
{
return false;
}
public bool IsTrue()
{
return true;
}
}
}
To run a specification you issue the following the command prompt: NSpec.Console /assembly:YourAssemblyFileName.dll [/output:YourXmlOutputFileName.xml] [/behaviourOutput:YourTextSpecFileName.txt]
Here is an example of the using NSpec to spec the TestObject from the console's command prompt:
In addition to the output to the console, NSpec provides a standard text file and an XML format report. Here are the standard text and XML reports from the spec above.
NSpec: NSpec 2006.1
Runtime: 2.0.50727.42
OS: Microsoft Windows NT 5.1.2600 Service Pack 2
Assembly:C:\Documents and Settings\mark\My Documents\Visual Studio 2005\NSpec\bin\debug\NSpecTest.dll
How BD DShould Be Done
* Behavior Driven Development Describes Behavior In Specs
* Specs Are Understood By Business Line
<?xml version="1.0" encoding="utf-8" ?>
<NSpec>
<Info>
<NSpec>NSpec 2006.1</NSpec>
<Runtime>2.0.50727.42</Runtime>
<OS>Microsoft Windows NT 5.1.2600 Service Pack 2</OS>
<Assembly Name="C:\Documents and Settings\mark\My Documents\Visual Studio 2005\NSpec\bin\debug\NSpecTest.dll">
<HowBDDShouldBeDone>
<BehaviorDrivenDevelopmentDescribesBehaviorInSpecs>
<Result>Passed</Result>
</BehaviorDrivenDevelopmentDescribesBehaviorInSpecs>
<SpecsAreUnderstoodByBusinessLine>
<Result>Passed</Result>
</SpecsAreUnderstoodByBusinessLine>
</HowBDDShouldBeDone>
</Assembly>
</Info>
</NSpec>