Skip to content

Commit 86ce5e7

Browse files
committed
Allow excluding of inputs from step title from attribute
1 parent 8c5c9cb commit 86ce5e7

3 files changed

Lines changed: 29 additions & 2 deletions

File tree

TestStack.BDDfy.Tests/Scanner/FluentScanner/StepTitleTests.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,14 @@ public void MethodCallInStepTitle()
1818
.When(_ => something.Sub.SomethingHappens())
1919
.And(_ => something.Sub.SomethingWithDifferentTitle())
2020
.Then(_ => ThenTitleHas(AMethodCall()))
21+
.And(_ => something.Sub.SomethingWithArg("foo"))
22+
.And(_ => something.Sub.SomethingWithArg2("foo"))
2123
.BDDfy();
2224

2325
story.Scenarios.Single().Steps.ElementAt(2).Title.ShouldBe("And different title");
2426
story.Scenarios.Single().Steps.ElementAt(3).Title.ShouldBe("Then title has Mutated state");
27+
story.Scenarios.Single().Steps.ElementAt(4).Title.ShouldBe("And with arg foo");
28+
story.Scenarios.Single().Steps.ElementAt(5).Title.ShouldBe("And with arg");
2529
}
2630

2731
public class FooClass
@@ -45,6 +49,16 @@ public void SomethingHappens()
4549
public void SomethingWithDifferentTitle()
4650
{
4751
}
52+
53+
[StepTitle("With arg")]
54+
public void SomethingWithArg(string arg)
55+
{
56+
}
57+
58+
[StepTitle("With arg", false)]
59+
public void SomethingWithArg2(string arg)
60+
{
61+
}
4862
}
4963

5064
private string AMethodCall()

TestStack.BDDfy/Scanners/StepScanners/Fluent/FluentScanner.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,12 @@ private StepTitle CreateTitle(string stepTextTemplate, bool includeInputsInStepT
154154
var name = methodInfo.Name;
155155
var stepTitleAttribute = methodInfo.GetCustomAttributes(typeof(StepTitleAttribute), true).SingleOrDefault();
156156
if (stepTitleAttribute != null)
157-
name = ((StepTitleAttribute)stepTitleAttribute).StepTitle;
157+
{
158+
var titleAttribute = ((StepTitleAttribute)stepTitleAttribute);
159+
name = titleAttribute.StepTitle;
160+
if (titleAttribute.IncludeInputsInStepTitle != null)
161+
includeInputsInStepTitle = titleAttribute.IncludeInputsInStepTitle.Value;
162+
}
158163

159164
var stepTitle = AppendPrefix(Configurator.Scanners.Humanize(name), stepPrefix);
160165

TestStack.BDDfy/StepTitleAttribute.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,17 @@ public class StepTitleAttribute : Attribute
77
{
88
public StepTitleAttribute(string stepTitle)
99
{
10-
this.StepTitle = stepTitle;
10+
StepTitle = stepTitle;
11+
}
12+
13+
public StepTitleAttribute(string stepTitle, bool includeInputsInStepTitle)
14+
{
15+
IncludeInputsInStepTitle = includeInputsInStepTitle;
16+
StepTitle = stepTitle;
1117
}
1218

1319
public string StepTitle { get; private set; }
20+
21+
public bool? IncludeInputsInStepTitle { get; private set; }
1422
}
1523
}

0 commit comments

Comments
 (0)