Skip to content

Commit 43ff2a6

Browse files
committed
added but to method name conventions
1 parent a144a87 commit 43ff2a6

File tree

2 files changed

+28
-108
lines changed

2 files changed

+28
-108
lines changed

TestStack.BDDfy.Tests/Scanner/WhenTestClassFollowsGivenWhenThenNamingConvention.cs

Lines changed: 25 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
namespace TestStack.BDDfy.Tests.Scanner
66
{
7-
// ToDo: I really need to clean this class up
87
[TestFixture]
98
public class WhenTestClassFollowsGivenWhenThenNamingConvention
109
{
@@ -29,19 +28,36 @@ public void TearDown(){}
2928
public void And_YET_another_thing(){}
3029
public void AndThen_something_else() {}
3130
public void And_then_there_was_that_one_time() {}
31+
public void But_some_condition_is_not_true() {}
32+
public void ButSomeOtherConditionIsNotTrue() {}
3233
}
3334

34-
[SetUp]
35-
public void Setup()
35+
[Test]
36+
public void VerifyScannedSteps()
3637
{
3738
_typeWithoutAttribute = new TypeWithoutAttribute();
3839
_steps = new DefaultMethodNameStepScanner().Scan(TestContext.GetContext(_typeWithoutAttribute)).ToList();
39-
}
40-
41-
[Test]
42-
public void AllMethodsFollowingTheNamingConventionAreReturnedAsSteps()
43-
{
44-
Assert.That(_steps.Count, Is.EqualTo(16));
40+
int stepIndex = 0;
41+
42+
Assert.That(_steps.Count, Is.EqualTo(18));
43+
AssertStep(_steps[stepIndex++], "Establish context", ExecutionOrder.Initialize, false, false);
44+
AssertStep(_steps[stepIndex++], "Setup", ExecutionOrder.Initialize, false, false);
45+
AssertStep(_steps[stepIndex++], "Given some state", ExecutionOrder.SetupState);
46+
AssertStep(_steps[stepIndex++], "And another state", ExecutionOrder.ConsecutiveSetupState);
47+
AssertStep(_steps[stepIndex++], "And Some OTHER state", ExecutionOrder.ConsecutiveSetupState);
48+
AssertStep(_steps[stepIndex++], "And some other initial state", ExecutionOrder.ConsecutiveSetupState);
49+
AssertStep(_steps[stepIndex++], "When something happens", ExecutionOrder.Transition);
50+
AssertStep(_steps[stepIndex++], "And something else happens", ExecutionOrder.ConsecutiveTransition);
51+
AssertStep(_steps[stepIndex++], "And another THING Happens", ExecutionOrder.ConsecutiveTransition);
52+
AssertStep(_steps[stepIndex++], "Then something is true", ExecutionOrder.Assertion, true);
53+
AssertStep(_steps[stepIndex++], "And another thing is true", ExecutionOrder.ConsecutiveAssertion, true);
54+
AssertStep(_steps[stepIndex++], "And something else too", ExecutionOrder.ConsecutiveAssertion, true);
55+
AssertStep(_steps[stepIndex++], "And YET another thing", ExecutionOrder.ConsecutiveAssertion, true);
56+
AssertStep(_steps[stepIndex++], "And something else", ExecutionOrder.ConsecutiveAssertion, true);
57+
AssertStep(_steps[stepIndex++], "And there was that one time", ExecutionOrder.ConsecutiveAssertion, true);
58+
AssertStep(_steps[stepIndex++], "But some condition is not true", ExecutionOrder.ConsecutiveAssertion, true);
59+
AssertStep(_steps[stepIndex++], "But some other condition is not true", ExecutionOrder.ConsecutiveAssertion, true);
60+
AssertStep(_steps[stepIndex++], "Tear down", ExecutionOrder.TearDown, asserts:false, shouldReport:false);
4561
}
4662

4763
private static void AssertStep(Step step, string stepTitle, ExecutionOrder order, bool asserts = false, bool shouldReport = true)
@@ -51,101 +67,5 @@ private static void AssertStep(Step step, string stepTitle, ExecutionOrder order
5167
Assert.That(step.ExecutionOrder, Is.EqualTo(order));
5268
Assert.That(step.ShouldReport, Is.EqualTo(shouldReport));
5369
}
54-
55-
[Test]
56-
public void EndsWithContext_IsReturnedFirst()
57-
{
58-
AssertStep(_steps[0], "Establish context", ExecutionOrder.Initialize, false, false);
59-
}
60-
61-
[Test]
62-
public void Setup_IsReturnedSecond()
63-
{
64-
AssertStep(_steps[1], "Setup", ExecutionOrder.Initialize, false, false);
65-
}
66-
67-
[Test]
68-
public void Given_IsTurnedIntoA_Given_Step()
69-
{
70-
AssertStep(_steps[2], "Given some state", ExecutionOrder.SetupState);
71-
}
72-
73-
[Test]
74-
public void AndGiven_IsTurnedIntoAn_AndGiven_Step()
75-
{
76-
AssertStep(_steps[3], "And another state", ExecutionOrder.ConsecutiveSetupState);
77-
}
78-
79-
[Test]
80-
public void And_Given_IsTurnedIntoAn_AndGiven_Step()
81-
{
82-
AssertStep(_steps[4], "And Some OTHER state", ExecutionOrder.ConsecutiveSetupState);
83-
}
84-
85-
[Test]
86-
public void AndGiven_InAnUnderscoredMethod_IsTurnedIntoAn_AndGiven_Step()
87-
{
88-
AssertStep(_steps[5], "And some other initial state", ExecutionOrder.ConsecutiveSetupState);
89-
}
90-
91-
[Test]
92-
public void WhenIsReturnedAfterGivens()
93-
{
94-
AssertStep(_steps[6], "When something happens", ExecutionOrder.Transition);
95-
}
96-
97-
[Test]
98-
public void AndWhenIsTurnedIntoAn_AndWhen_Step()
99-
{
100-
AssertStep(_steps[7], "And something else happens", ExecutionOrder.ConsecutiveTransition);
101-
}
102-
103-
[Test]
104-
public void And_When_IsTurnedIntoAn_AndWhen_Step()
105-
{
106-
AssertStep(_steps[8], "And another THING Happens", ExecutionOrder.ConsecutiveTransition);
107-
}
108-
109-
[Test]
110-
public void ThenIsReturnedAfterWhens()
111-
{
112-
AssertStep(_steps[9], "Then something is true", ExecutionOrder.Assertion, true);
113-
}
114-
115-
[Test]
116-
public void AndThen_IsReturnedAsAn_AndThen_StepAfterThen()
117-
{
118-
AssertStep(_steps[10], "And another thing is true", ExecutionOrder.ConsecutiveAssertion, true);
119-
}
120-
121-
[Test]
122-
public void And_IsReturnedAsAn_AndThen_Step()
123-
{
124-
AssertStep(_steps[11], "And something else too", ExecutionOrder.ConsecutiveAssertion, true);
125-
}
126-
127-
[Test]
128-
public void And_IsReturnedAsAn_AndThen_WithTheRightCasing()
129-
{
130-
AssertStep(_steps[12], "And YET another thing", ExecutionOrder.ConsecutiveAssertion, true);
131-
}
132-
133-
[Test]
134-
public void AndThen_IsReturnedAsAn_AndThen_WithUnderscoredMethodName()
135-
{
136-
AssertStep(_steps[13], "And something else", ExecutionOrder.ConsecutiveAssertion, true);
137-
}
138-
139-
[Test]
140-
public void And_Then_IsReturnedAsAn_AndThen_WithUnderscoredMethodName()
141-
{
142-
AssertStep(_steps[14], "And there was that one time", ExecutionOrder.ConsecutiveAssertion, true);
143-
}
144-
145-
[Test]
146-
public void TearDownMethodIsReturnedInTheCorrectSpot()
147-
{
148-
AssertStep(_steps[15], "Tear down", ExecutionOrder.TearDown, asserts:false, shouldReport:false);
149-
}
15070
}
15171
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ namespace TestStack.BDDfy
55
public class DefaultMethodNameStepScanner : MethodNameStepScanner
66
{
77
public DefaultMethodNameStepScanner()
8-
: base(
9-
CleanupTheStepText,
8+
: base(CleanupTheStepText,
109
new[]
1110
{
1211
new MethodNameMatcher(s => s.EndsWith("Context", StringComparison.OrdinalIgnoreCase), false, ExecutionOrder.Initialize, false),
@@ -21,7 +20,8 @@ public DefaultMethodNameStepScanner()
2120
new MethodNameMatcher(s => s.StartsWith("And", StringComparison.OrdinalIgnoreCase), true, ExecutionOrder.ConsecutiveAssertion, true),
2221
new MethodNameMatcher(s => s.StartsWith("AndThen", StringComparison.OrdinalIgnoreCase), true, ExecutionOrder.ConsecutiveAssertion, true),
2322
new MethodNameMatcher(s => s.StartsWith("And_Then_", StringComparison.OrdinalIgnoreCase), true, ExecutionOrder.ConsecutiveAssertion, true),
24-
new MethodNameMatcher(s => s.StartsWith("TearDown", StringComparison.OrdinalIgnoreCase), false, ExecutionOrder.TearDown, false),
23+
new MethodNameMatcher(s => s.StartsWith("But", StringComparison.OrdinalIgnoreCase), true, ExecutionOrder.ConsecutiveAssertion, true),
24+
new MethodNameMatcher(s => s.StartsWith("TearDown", StringComparison.OrdinalIgnoreCase), false, ExecutionOrder.TearDown, false)
2525
})
2626
{
2727
}

0 commit comments

Comments
 (0)