Skip to content

Commit

Permalink
DefaultConvention foo
Browse files Browse the repository at this point in the history
  • Loading branch information
mattflo committed May 10, 2011
1 parent b7a2d67 commit 336bb30
Show file tree
Hide file tree
Showing 14 changed files with 161 additions and 544 deletions.
18 changes: 18 additions & 0 deletions NSpec/Domain/DefaultConvention.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System.Text.RegularExpressions;

namespace NSpec.Domain
{
public class DefaultConvention : Conventions
{
public override void SpecifyConventions(ConventionSpecification specification)
{
specification.SetBefore(new Regex("before_each|BeforeEach"));

specification.SetAct(new Regex("act_each|ActEach"));

specification.SetExample(new Regex("(^[iI]t[_A-Z])|(^[sS]pecify)"));

specification.SetContext(new Regex(""));
}
}
}
19 changes: 0 additions & 19 deletions NSpec/Domain/UnderScore.cs

This file was deleted.

2 changes: 1 addition & 1 deletion NSpec/NSpec.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
<Compile Include="Domain\MethodContext.cs" />
<Compile Include="Domain\PendingExampleException.cs" />
<Compile Include="Domain\ExceptionNotThrown.cs" />
<Compile Include="Domain\UnderScore.cs" />
<Compile Include="Domain\DefaultConvention.cs" />
<Compile Include="Each.cs" />
<Compile Include="Domain\ActionIndexer.cs" />
<Compile Include="nspec.cs" />
Expand Down
9 changes: 1 addition & 8 deletions NSpecRunner/Program.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Net.Mime;
using System.Reflection;
using NSpec;
using NSpec.Domain;
Expand All @@ -21,15 +20,9 @@ static void Main(string[] args)

var finder = new SpecFinder(args[0], new Reflector(), classFilter);

//var finder = new SpecFinder(@"C:\Development\GameTrader\GameTrader.Specs\bin\Debug\GameTrader.Specs.dll", new Reflector(), "describe_AuthenticationController");

//var finder = new SpecFinder(@"C:\Development\nspec\samplespecs\bin\debug\samplespecs.dll", new Reflector(), "");

var builder = new ContextBuilder(finder, new UnderScore());
var builder = new ContextBuilder(finder, new DefaultConvention());

new ContextRunner(builder).Run();

//new ContextRunner(new ContextBuilder(new SpecFinder(@"C:\Development\GameTrader\GameTrader.Specs\bin\Debug\GameTrader.Specs.dll", new Reflector()))).Run();
}
catch (Exception e)
{
Expand Down
3 changes: 1 addition & 2 deletions NSpecSpecs/NSpecSpecs.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="describe_ClassContext.cs" />
<Compile Include="describe_Conventions.cs" />
<Compile Include="describe_RunningSpecs\describe_method_level_examples.cs" />
<Compile Include="describe_RunningSpecs\describe_xdescribe.cs" />
Expand All @@ -61,7 +60,7 @@
<Compile Include="describe_RunningSpecs\describe_implicit_befores.cs" />
<Compile Include="describe_RunningSpecs\describe_todo.cs" />
<Compile Include="describe_ContextCollection.cs" />
<Compile Include="describe_UnderScore.cs" />
<Compile Include="describe_DefaultConvention.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="describe_RunningSpecs\when_act_contains_exception.cs" />
<Compile Include="describe_RunningSpecs\when_after_contains_exception.cs" />
Expand Down
14 changes: 0 additions & 14 deletions NSpecSpecs/describe_ClassContext.cs

This file was deleted.

12 changes: 6 additions & 6 deletions NSpecSpecs/describe_Context.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public class when_creating_act_contexts_for_derived_class
[SetUp]
public void setup()
{
conventions = new UnderScore();
conventions = new DefaultConvention();

conventions.Initialize();

Expand Down Expand Up @@ -99,7 +99,7 @@ public void it_should_also_set_the_proper_before_on_ancestors()

private ClassContext childContext;

private UnderScore conventions;
private DefaultConvention conventions;

private ClassContext parentContext;

Expand Down Expand Up @@ -130,7 +130,7 @@ public class when_creating_contexts_for_derived_classes
[SetUp]
public void setup()
{
conventions = new UnderScore();
conventions = new DefaultConvention();

conventions.Initialize();

Expand Down Expand Up @@ -159,7 +159,7 @@ public void it_should_have_the_child_as_a_context()

private ClassContext childContext;

private UnderScore conventions;
private DefaultConvention conventions;

private ClassContext parentContext;
}
Expand All @@ -171,7 +171,7 @@ public class when_creating_before_contexts_for_derived_class
[SetUp]
public void setup()
{
conventions = new UnderScore();
conventions = new DefaultConvention();

conventions.Initialize();

Expand Down Expand Up @@ -210,7 +210,7 @@ public void it_should_also_set_the_proper_before_on_ancestors()

private ClassContext childContext;

private UnderScore conventions;
private DefaultConvention conventions;

private ClassContext parentContext;

Expand Down
19 changes: 4 additions & 15 deletions NSpecSpecs/describe_ContextBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public void setup_base()

finder.Stub(f => f.SpecClasses()).IgnoreArguments().Return(typesForFinder);

UnderScore conventions = new UnderScore();
DefaultConvention conventions = new DefaultConvention();

conventions.Initialize();

Expand All @@ -46,17 +46,6 @@ public IList<Context> TheContexts()
}
}

[TestFixture]
[Category("ContextBuilder")]
public class when_finding_method_level_befores
{
[SetUp]
public void Setup()
{

}
}

[TestFixture]
[Category("ContextBuilder")]
public class when_building_contexts : describe_ContextBuilder
Expand Down Expand Up @@ -170,11 +159,11 @@ public void setup()
{
var finder = MockRepository.GenerateMock<ISpecFinder>();

UnderScore underScoreConventions = new UnderScore();
DefaultConvention defaultConvention = new DefaultConvention();

underScoreConventions.Initialize();
defaultConvention.Initialize();

var builder = new ContextBuilder(finder, underScoreConventions);
var builder = new ContextBuilder(finder, defaultConvention);

classContext = new Context("class");

Expand Down
2 changes: 1 addition & 1 deletion NSpecSpecs/describe_Conventions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ void before_each()
[SetUp]
public void Setup()
{
convensions = new UnderScore();
convensions = new DefaultConvention();
}
}

Expand Down
126 changes: 126 additions & 0 deletions NSpecSpecs/describe_DefaultConvention.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
using NUnit.Framework;
using NSpec.Domain;
using NSpec;

namespace NSpecSpecs
{
public class describe_DefaultConvention
{
protected Conventions underScore;

[SetUp]
public void setup_base()
{
underScore = new DefaultConvention();

underScore.Initialize();
}
}

[TestFixture]
[Category("DefaultConvention")]
public class when_determining_before_methods : describe_DefaultConvention
{
[Test]
public void should_match_before_each()
{
ShouldBeBefore("before_each");
}

[Test]
public void should_match_BeforeEach()
{
ShouldBeBefore("BeforeEach");
}

void ShouldBeBefore(string methodName)
{
underScore.IsMethodLevelBefore(methodName).should_be_true();

underScore.IsMethodLevelContext(methodName).should_be_false();
}
}

[TestFixture]
[Category("DefaultConvention")]
public class when_determining_act_methods : describe_DefaultConvention
{
[Test]
public void should_match_act_each()
{
ShouldBeAct("act_each");
}

[Test]
public void should_match_ActEach()
{
ShouldBeAct("ActEach");
}

void ShouldBeAct(string methodName)
{
underScore.IsMethodLevelAct(methodName).should_be_true();

underScore.IsMethodLevelContext(methodName).should_be_false();
}
}

[TestFixture]
[Category("DefaultConvention")]
public class when_determining_example_methods : describe_DefaultConvention
{
[Test]
public void should_match_it()
{
ShouldBeExample("it_should_be_true");
}

[Test]
public void should_match_specify()
{
ShouldBeExample("specify_should_be_true");
}

[Test]
public void should_match_ItShouldBeTrue()
{
ShouldBeExample("ItShouldBeTrue");
}

[Test]
public void should_match_SpecifyShouldBeTrue()
{
ShouldBeExample("SpecifyShouldBeTrue");
}

[Test]
public void should_not_match_IterationShould()
{
underScore.IsMethodLevelExample("IterationShould").should_be_false();
}

void ShouldBeExample(string methodName)
{
underScore.IsMethodLevelExample(methodName).should_be_true();

underScore.IsMethodLevelContext(methodName).should_be_false();
}
}

[TestFixture]
[Category("DefaultConvention")]
public class when_determining_context_methods : describe_DefaultConvention
{
[Test]
public void should_be_match_describe_a_specification()
{
underScore.IsMethodLevelContext("describe_a_specification").should_be_true();
}

[Test]
public void should_be_match_DescribeASpecification()
{
underScore.IsMethodLevelContext("DescribeASpecification").should_be_true();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public void setup()

RhinoMocksExtensions.Stub(reflector, r => r.GetTypesFrom("")).IgnoreArguments().Return(new[] { typeof(SpecClass) });

var contextBuilder = new ContextBuilder(new SpecFinder("", reflector), new UnderScore());
var contextBuilder = new ContextBuilder(new SpecFinder("", reflector), new DefaultConvention());

classContext = contextBuilder.Contexts().First();

Expand Down
4 changes: 2 additions & 2 deletions NSpecSpecs/describe_RunningSpecs/when_running_specs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class when_running_specs
[SetUp]
public void setup_base()
{
convention = new UnderScore();
convention = new DefaultConvention();

convention.Initialize();
}
Expand Down Expand Up @@ -43,7 +43,7 @@ protected void Run(Type type, string methodName)
}

protected ClassContext classContext;
private UnderScore convention;
private DefaultConvention convention;
protected Context methodContext;
}
}
Loading

0 comments on commit 336bb30

Please sign in to comment.