Skip to content

Commit ce426c8

Browse files
committed
Merge pull request #193 from mwhelan/master
Added ShouldReport to ExecutableAttribute
2 parents cc8f02d + 6ba6531 commit ce426c8

File tree

3 files changed

+27
-4
lines changed

3 files changed

+27
-4
lines changed

TestStack.BDDfy.Tests/Scanner/ReflectiveScanner/WhenTestClassUsesExecutableAttributes.cs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ public void SomeOtherPartOfTheGiven() { }
5454

5555
[But]
5656
public void IDontWantThisToBeTrue() { }
57+
58+
[Executable(ExecutionOrder.Assertion, "", ShouldReport = false)]
59+
public void Executable() { }
5760
}
5861

5962
[SetUp]
@@ -71,7 +74,7 @@ private static string GetStepTextFromMethodName(Action methodInfoAction)
7174
[Test]
7275
public void DecoratedMethodsAreReturned()
7376
{
74-
Assert.That(_steps.Count, Is.EqualTo(10));
77+
Assert.That(_steps.Count, Is.EqualTo(11));
7578
}
7679

7780
[Test]
@@ -153,5 +156,21 @@ public void But()
153156
Assert.That(step.ExecutionOrder, Is.EqualTo(ExecutionOrder.ConsecutiveAssertion));
154157
Assert.IsTrue(step.Asserts);
155158
}
159+
160+
[Test]
161+
public void ExecutableAttributesDefaultToShouldReport()
162+
{
163+
foreach (var step in _steps.Where(s => s.Title != "Executable"))
164+
{
165+
Assert.IsTrue(step.ShouldReport);
166+
}
167+
}
168+
169+
[Test]
170+
public void CanPreventExecutableAttributesReporting()
171+
{
172+
var step = _steps.First(s => s.Title == "Executable");
173+
Assert.IsFalse(step.ShouldReport);
174+
}
156175
}
157176
}

TestStack.BDDfy/Scanners/StepScanners/ExecutableAttribute/ExecutableAttribute.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@ public ExecutableAttribute(ExecutionOrder order, string stepTitle)
99
{
1010
ExecutionOrder = order;
1111
StepTitle = stepTitle;
12+
ShouldReport = true;
1213
}
1314

1415
public ExecutionOrder ExecutionOrder { get; private set; }
1516
public bool Asserts { get; set; }
1617
public string StepTitle { get; set; }
1718
public int Order { get; set; }
19+
public bool ShouldReport { get; set; }
1820
}
1921
}

TestStack.BDDfy/Scanners/StepScanners/ExecutableAttribute/ExecutableAttributeStepScanner.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,13 @@ public IEnumerable<Step> Scan(ITestContext testContext, MethodInfo candidateMeth
3737
stepTitle = new StepTitle(Configurator.Scanners.Humanize(candidateMethod.Name));
3838

3939
var stepAsserts = IsAssertingByAttribute(candidateMethod);
40+
var shouldReport = executableAttribute.ShouldReport;
4041

4142
var runStepWithArgsAttributes = (RunStepWithArgsAttribute[])candidateMethod.GetCustomAttributes(typeof(RunStepWithArgsAttribute), true);
4243
if (runStepWithArgsAttributes.Length == 0)
4344
{
4445
var stepAction = StepActionFactory.GetStepAction(candidateMethod, new object[0]);
45-
yield return new Step(stepAction, stepTitle, stepAsserts, executableAttribute.ExecutionOrder, true, new List<StepArgument>())
46+
yield return new Step(stepAction, stepTitle, stepAsserts, executableAttribute.ExecutionOrder, shouldReport, new List<StepArgument>())
4647
{
4748
ExecutionSubOrder = executableAttribute.Order
4849
};
@@ -62,7 +63,7 @@ public IEnumerable<Step> Scan(ITestContext testContext, MethodInfo candidateMeth
6263

6364
var stepAction = StepActionFactory.GetStepAction(candidateMethod, inputArguments);
6465
yield return new Step(stepAction, new StepTitle(methodName), stepAsserts,
65-
executableAttribute.ExecutionOrder, true, new List<StepArgument>())
66+
executableAttribute.ExecutionOrder, shouldReport, new List<StepArgument>())
6667
{
6768
ExecutionSubOrder = executableAttribute.Order
6869
};
@@ -80,6 +81,7 @@ public IEnumerable<Step> Scan(ITestContext testContext, MethodInfo method, Examp
8081
stepTitle = Configurator.Scanners.Humanize(method.Name);
8182

8283
var stepAsserts = IsAssertingByAttribute(method);
84+
var shouldReport = executableAttribute.ShouldReport;
8385
var methodParameters = method.GetParameters();
8486

8587
var inputs = new List<object>();
@@ -100,7 +102,7 @@ public IEnumerable<Step> Scan(ITestContext testContext, MethodInfo method, Examp
100102
}
101103

102104
var stepAction = StepActionFactory.GetStepAction(method, inputs.ToArray());
103-
yield return new Step(stepAction, new StepTitle(stepTitle), stepAsserts, executableAttribute.ExecutionOrder, true, new List<StepArgument>());
105+
yield return new Step(stepAction, new StepTitle(stepTitle), stepAsserts, executableAttribute.ExecutionOrder, shouldReport, new List<StepArgument>());
104106
}
105107

106108

0 commit comments

Comments
 (0)