Skip to content

Commit dc8a8b5

Browse files
committed
✨ NSpec
1 parent 217e02c commit dc8a8b5

File tree

6 files changed

+110
-0
lines changed

6 files changed

+110
-0
lines changed

BDD/ConductOfCode/ConductOfCode/ConductOfCode.csproj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@
5050
<HintPath>..\packages\Machine.Specifications.Should.0.9.0\lib\net45\Machine.Specifications.Should.dll</HintPath>
5151
<Private>True</Private>
5252
</Reference>
53+
<Reference Include="NSpec, Version=1.0.7.0, Culture=neutral, processorArchitecture=MSIL">
54+
<HintPath>..\packages\nspec.1.0.7\lib\NSpec.dll</HintPath>
55+
<Private>True</Private>
56+
</Reference>
5357
<Reference Include="nunit.framework, Version=2.6.3.13283, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
5458
<HintPath>..\packages\NUnit.2.6.3\lib\nunit.framework.dll</HintPath>
5559
<Private>True</Private>
@@ -64,14 +68,17 @@
6468
<Reference Include="System.Xml" />
6569
</ItemGroup>
6670
<ItemGroup>
71+
<Compile Include="DebuggerShim.cs" />
6772
<Compile Include="LightBDD\Stack_feature.cs" />
6873
<Compile Include="LightBDD\Stack_feature.Steps.cs">
6974
<DependentUpon>Stack_feature.cs</DependentUpon>
7075
</Compile>
7176
<Compile Include="MSpec\StackSpecs.cs" />
77+
<Compile Include="NSpec\stack_specs.cs" />
7278
<Compile Include="Properties\AssemblyInfo.cs" />
7379
</ItemGroup>
7480
<ItemGroup>
81+
<None Include="app.config" />
7582
<None Include="packages.config" />
7683
</ItemGroup>
7784
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
using System.Linq;
2+
using System.Reflection;
3+
using NSpec;
4+
using NSpec.Domain;
5+
using NSpec.Domain.Formatters;
6+
7+
/*
8+
* Howdy,
9+
*
10+
* This is NSpec's DebuggerShim. It will allow you to use TestDriven.Net or Resharper's test runner to run
11+
* NSpec tests that are in the same Assembly as this class.
12+
*
13+
* It's DEFINITELY worth trying specwatchr (http://nspec.org/continuoustesting). Specwatchr automatically
14+
* runs tests for you.
15+
*
16+
* If you ever want to debug a test when using Specwatchr, simply put the following line in your test:
17+
*
18+
* System.Diagnostics.Debugger.Launch()
19+
*
20+
* Visual Studio will detect this and will give you a window which you can use to attach a debugger.
21+
*/
22+
23+
//[TestFixture]
24+
public class DebuggerShim
25+
{
26+
//[Test]
27+
public void debug()
28+
{
29+
var tagOrClassName = "class_or_tag_you_want_to_debug";
30+
31+
var types = GetType().Assembly.GetTypes();
32+
// OR
33+
// var types = new Type[]{typeof(Some_Type_Containg_some_Specs)};
34+
35+
var finder = new SpecFinder(types, "");
36+
37+
var tagsFilter = new Tags().Parse(tagOrClassName);
38+
39+
var builder = new ContextBuilder(finder, tagsFilter, new DefaultConventions());
40+
41+
var runner = new ContextRunner(tagsFilter, new ConsoleFormatter(), false);
42+
43+
var results = runner.Run(builder.Contexts().Build());
44+
45+
//assert that there aren't any failures
46+
results.Failures().Count().should_be(0);
47+
}
48+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# NSpec
2+
3+
* Dependencies: -
4+
* NuGet: https://www.nuget.org/packages/nspec/
5+
* Source: https://github.com/mattflo/nspec
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using NSpec;
4+
5+
namespace ConductOfCode.NSpec
6+
{
7+
class stack_specs : nspec
8+
{
9+
void empty_()
10+
{
11+
before = () => stack = new Stack<int>();
12+
13+
it["has no elements"] = () => stack.Count.should_be(0);
14+
it["throws an exception when calling pop"] = () => expect<InvalidOperationException>(() => stack.Pop());
15+
it["throws an exception when calling peek"] = () => expect<InvalidOperationException>(() => stack.Peek());
16+
}
17+
18+
void not_empty()
19+
{
20+
before = () => stack = new Stack<int>(new[] { 1, 2, 3 });
21+
22+
it["returns the top element when calling peek"] = () => stack.Peek().should_be(3);
23+
it["does not remove the top element when calling peek"] = () =>
24+
{
25+
stack.Peek();
26+
stack.should_contain(3);
27+
};
28+
it["returns the top element when calling pop"] = () => stack.Pop().should_be(3);
29+
it["removes the top element when calling pop"] = () =>
30+
{
31+
stack.Pop();
32+
stack.should_not_contain(3);
33+
};
34+
}
35+
36+
Stack<int> stack;
37+
}
38+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<configuration>
3+
<runtime>
4+
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
5+
<dependentAssembly>
6+
<assemblyIdentity name="nunit.framework" publicKeyToken="96d09a1eb7f44a77" culture="neutral" />
7+
<bindingRedirect oldVersion="0.0.0.0-2.6.3.13283" newVersion="2.6.3.13283" />
8+
</dependentAssembly>
9+
</assemblyBinding>
10+
</runtime>
11+
</configuration>

BDD/ConductOfCode/ConductOfCode/packages.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@
55
<package id="LightBDD.NUnit" version="1.7.1.0" targetFramework="net46" />
66
<package id="Machine.Specifications" version="0.9.3" targetFramework="net46" />
77
<package id="Machine.Specifications.Should" version="0.9.0" targetFramework="net46" />
8+
<package id="nspec" version="1.0.7" targetFramework="net46" />
89
<package id="NUnit" version="2.6.3" targetFramework="net46" />
910
</packages>

0 commit comments

Comments
 (0)