Skip to content

Commit 1c37dc6

Browse files
committed
Added ExecutionOrder.Initialize to distinguish Context/Setup from Given
1 parent 2102321 commit 1c37dc6

File tree

3 files changed

+40
-25
lines changed

3 files changed

+40
-25
lines changed

TestStack.BDDfy.Tests/Scanner/WhenTestClassFollowsGivenWhenThenNamingConvention.cs

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ public class WhenTestClassFollowsGivenWhenThenNamingConvention
1515

1616
private class TypeWithoutAttribute
1717
{
18+
public void EstablishContext() {}
19+
public void Setup(){}
1820
public void AndThenAnotherThingIsTrue() {}
1921
public void AndWhenSomethingElseHappens() {}
2022
public void And_When_another_THING_Happens() {}
@@ -41,7 +43,7 @@ public void Setup()
4143
[Test]
4244
public void AllMethodsFollowingTheNamingConventionAreReturnedAsSteps()
4345
{
44-
Assert.That(_steps.Count, Is.EqualTo(14));
46+
Assert.That(_steps.Count, Is.EqualTo(16));
4547
}
4648

4749
private static void AssertStep(ExecutionStep step, string stepTitle, ExecutionOrder order, bool asserts = false, bool shouldReport = true)
@@ -53,87 +55,99 @@ private static void AssertStep(ExecutionStep step, string stepTitle, ExecutionOr
5355
}
5456

5557
[Test]
56-
public void GivenIsReturnedFirst()
58+
public void EndsWithContext_IsReturnedFirst()
5759
{
58-
AssertStep(_steps[0], "Given some state", ExecutionOrder.SetupState);
60+
AssertStep(_steps[0], "Establish context", ExecutionOrder.Initialize, false, false);
61+
}
62+
63+
[Test]
64+
public void Setup_IsReturnedSecond()
65+
{
66+
AssertStep(_steps[1], "Setup", ExecutionOrder.Initialize, false, false);
67+
}
68+
69+
[Test]
70+
public void Given_IsTurnedIntoA_Given_Step()
71+
{
72+
AssertStep(_steps[2], "Given some state", ExecutionOrder.SetupState);
5973
}
6074

6175
[Test]
6276
public void AndGiven_IsTurnedIntoAn_AndGiven_Step()
6377
{
64-
AssertStep(_steps[1], "And another state", ExecutionOrder.ConsecutiveSetupState);
78+
AssertStep(_steps[3], "And another state", ExecutionOrder.ConsecutiveSetupState);
6579
}
6680

6781
[Test]
6882
public void And_Given_IsTurnedIntoAn_AndGiven_Step()
6983
{
70-
AssertStep(_steps[2], "And Some OTHER state", ExecutionOrder.ConsecutiveSetupState);
84+
AssertStep(_steps[4], "And Some OTHER state", ExecutionOrder.ConsecutiveSetupState);
7185
}
7286

7387
[Test]
7488
public void AndGiven_InAnUnderscoredMethod_IsTurnedIntoAn_AndGiven_Step()
7589
{
76-
AssertStep(_steps[3], "And some other initial state", ExecutionOrder.ConsecutiveSetupState);
90+
AssertStep(_steps[5], "And some other initial state", ExecutionOrder.ConsecutiveSetupState);
7791
}
7892

7993
[Test]
8094
public void WhenIsReturnedAfterGivens()
8195
{
82-
AssertStep(_steps[4], "When something happens", ExecutionOrder.Transition);
96+
AssertStep(_steps[6], "When something happens", ExecutionOrder.Transition);
8397
}
8498

8599
[Test]
86100
public void AndWhenIsTurnedIntoAn_AndWhen_Step()
87101
{
88-
AssertStep(_steps[5], "And something else happens", ExecutionOrder.ConsecutiveTransition);
102+
AssertStep(_steps[7], "And something else happens", ExecutionOrder.ConsecutiveTransition);
89103
}
90104

91105
[Test]
92106
public void And_When_IsTurnedIntoAn_AndWhen_Step()
93107
{
94-
AssertStep(_steps[6], "And another THING Happens", ExecutionOrder.ConsecutiveTransition);
108+
AssertStep(_steps[8], "And another THING Happens", ExecutionOrder.ConsecutiveTransition);
95109
}
96110

97111
[Test]
98112
public void ThenIsReturnedAfterWhens()
99113
{
100-
AssertStep(_steps[7], "Then something is true", ExecutionOrder.Assertion, true);
114+
AssertStep(_steps[9], "Then something is true", ExecutionOrder.Assertion, true);
101115
}
102116

103117
[Test]
104118
public void AndThen_IsReturnedAsAn_AndThen_StepAfterThen()
105119
{
106-
AssertStep(_steps[8], "And another thing is true", ExecutionOrder.ConsecutiveAssertion, true);
120+
AssertStep(_steps[10], "And another thing is true", ExecutionOrder.ConsecutiveAssertion, true);
107121
}
108122

109123
[Test]
110124
public void And_IsReturnedAsAn_AndThen_Step()
111125
{
112-
AssertStep(_steps[9], "And something else too", ExecutionOrder.ConsecutiveAssertion, true);
126+
AssertStep(_steps[11], "And something else too", ExecutionOrder.ConsecutiveAssertion, true);
113127
}
114128

115129
[Test]
116130
public void And_IsReturnedAsAn_AndThen_WithTheRightCasing()
117131
{
118-
AssertStep(_steps[10], "And YET another thing", ExecutionOrder.ConsecutiveAssertion, true);
132+
AssertStep(_steps[12], "And YET another thing", ExecutionOrder.ConsecutiveAssertion, true);
119133
}
120134

121135
[Test]
122136
public void AndThen_IsReturnedAsAn_AndThen_WithUnderscoredMethodName()
123137
{
124-
AssertStep(_steps[11], "And something else", ExecutionOrder.ConsecutiveAssertion, true);
138+
AssertStep(_steps[13], "And something else", ExecutionOrder.ConsecutiveAssertion, true);
125139
}
126140

127141
[Test]
128142
public void And_Then_IsReturnedAsAn_AndThen_WithUnderscoredMethodName()
129143
{
130-
AssertStep(_steps[12], "And there was that one time", ExecutionOrder.ConsecutiveAssertion, true);
144+
AssertStep(_steps[14], "And there was that one time", ExecutionOrder.ConsecutiveAssertion, true);
131145
}
132146

133147
[Test]
134148
public void TearDownMethodIsReturnedInTheCorrectSpot()
135149
{
136-
AssertStep(_steps[13], "Tear down", ExecutionOrder.TearDown, asserts:false, shouldReport:false);
150+
AssertStep(_steps[15], "Tear down", ExecutionOrder.TearDown, asserts:false, shouldReport:false);
137151
}
138152
}
139153
}

TestStack.BDDfy/Core/ExecutionOrder.cs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,13 @@ namespace TestStack.BDDfy.Core
2727
{
2828
public enum ExecutionOrder
2929
{
30-
SetupState = 1,
31-
ConsecutiveSetupState = 2,
32-
Transition = 3,
33-
ConsecutiveTransition = 4,
34-
Assertion = 5,
35-
ConsecutiveAssertion = 6,
36-
TearDown = 7
30+
Initialize = 1,
31+
SetupState = 2,
32+
ConsecutiveSetupState = 3,
33+
Transition = 4,
34+
ConsecutiveTransition = 5,
35+
Assertion = 6,
36+
ConsecutiveAssertion = 7,
37+
TearDown = 8
3738
}
3839
}

TestStack.BDDfy/Scanners/StepScanners/MethodName/DefaultMethodNameStepScanner.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ public DefaultMethodNameStepScanner()
3535
CleanupTheStepText,
3636
new[]
3737
{
38-
new MethodNameMatcher(s => s.EndsWith("Context", StringComparison.OrdinalIgnoreCase), false, ExecutionOrder.SetupState, false),
39-
new MethodNameMatcher(s => s.Equals("Setup", StringComparison.OrdinalIgnoreCase), false, ExecutionOrder.SetupState, false),
38+
new MethodNameMatcher(s => s.EndsWith("Context", StringComparison.OrdinalIgnoreCase), false, ExecutionOrder.Initialize, false),
39+
new MethodNameMatcher(s => s.Equals("Setup", StringComparison.OrdinalIgnoreCase), false, ExecutionOrder.Initialize, false),
4040
new MethodNameMatcher(s => s.StartsWith("Given", StringComparison.OrdinalIgnoreCase), false, ExecutionOrder.SetupState, true),
4141
new MethodNameMatcher(s => s.StartsWith("AndGiven", StringComparison.OrdinalIgnoreCase), false, ExecutionOrder.ConsecutiveSetupState, true),
4242
new MethodNameMatcher(s => s.StartsWith("And_Given_", StringComparison.OrdinalIgnoreCase), false, ExecutionOrder.ConsecutiveSetupState, true),

0 commit comments

Comments
 (0)