Skip to content

Commit 52bc89d

Browse files
committed
Merge pull request #129 from JakeGinnivan/FormatLineFeedInTextReporter
Format line feed in text reporter
2 parents bc22ded + c54b23d commit 52bc89d

10 files changed

Lines changed: 27 additions & 25 deletions

TestStack.BDDfy.Tests/Reporters/Html/ClassicReportBuilderTests.ShouldProduceExpectedHtmlWithExamples.approved.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,9 @@ body{margin:0;padding:0;padding-bottom:40px;max-width:100%;background-color:#fff
111111
<td>negative</td>
112112
<td>is not</td>
113113
<td>
114-
<span class='canToggle' data-toggle-target='step-1-19'>Boom</span>
114+
<span class='canToggle' data-toggle-target='step-1-19'>Boom
115+
With
116+
New lines</span>
115117
<div class='step' id='step-1-19'>
116118
<code> at TestStack.BDDfy.Tests.Reporters.ReportTestData.GetScenarios(Boolean includeFailingScenario, Boolean includeExamples) in ...\ReportTestData.cs:line 113</code>
117119
</div>

TestStack.BDDfy.Tests/Reporters/Html/MetroReportBuilderTests.ShouldProduceExpectedHtmlWithExamples.approved.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,9 @@ html,body,div,span,applet,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre,a,abb
122122
<td>negative</td>
123123
<td>is not</td>
124124
<td>
125-
<span class='canToggle' data-toggle-target='step-1-19'>Boom</span>
125+
<span class='canToggle' data-toggle-target='step-1-19'>Boom
126+
With
127+
New lines</span>
126128
<div class='step FailedException' id='step-1-19'>
127129
<code> at TestStack.BDDfy.Tests.Reporters.ReportTestData.GetScenarios(Boolean includeFailingScenario, Boolean includeExamples) in ...\ReportTestData.cs:line 113</code>
128130
</div>

TestStack.BDDfy.Tests/Reporters/MarkDown/MarkDownReportBuilderTests.ShouldProduceExpectedMarkdownWithExamples.approved.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010

1111
### Examples:
1212

13-
| sign | action | Result | Errors |
14-
| positive | is | Passed | |
15-
| negative | is not | Failed | Step: Then money &lt;action&gt; dispensed failed with exception: [Boom] [Details at 1 below] |
13+
| sign | action | Result | Errors |
14+
| positive | is | Passed | |
15+
| negative | is not | Failed | Step: Then money &lt;action&gt; dispensed failed with exception: [Boom With New lines] [Details at 1 below] |
1616

1717
#### Exceptions:
18-
1. Boom
18+
1. Boom With New lines
1919
at TestStack.BDDfy.Tests.Reporters.ReportTestData.GetScenarios(Boolean includeFailingScenario, Boolean includeExamples) in ...\ReportTestData.cs:line 113
2020

2121
## Story: Happiness

TestStack.BDDfy.Tests/Reporters/ReportTestData.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ private Scenario[] GetScenarios(bool includeFailingScenario, bool includeExample
110110
last.Result = Result.Failed;
111111
try
112112
{
113-
throw new InvalidOperationException("Boom");
113+
throw new InvalidOperationException("Boom\nWith\r\nNew lines");
114114
}
115115
catch (Exception ex)
116116
{

TestStack.BDDfy.Tests/Reporters/TextReporter/TextReporterTests.ShouldProduceExpectedReport.approved.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,12 @@ Scenario: Example Scenario
8989
Then money <action> dispensed
9090

9191
Examples:
92-
| sign | action | Result | Errors |
93-
| positive | is | Passed | |
94-
| negative | is not | Failed | Step: Then money <action> dispensed failed with exception: [Boom] [Details at 1 below] |
92+
| sign | action | Result | Errors |
93+
| positive | is | Passed | |
94+
| negative | is not | Failed | Step: Then money <action> dispensed failed with exception: [Boom With New lines] [Details at 1 below] |
9595

9696
Exceptions:
97-
1. Boom
97+
1. Boom With New lines
9898
at TestStack.BDDfy.Tests.Reporters.ReportTestData.GetScenarios(Boolean includeFailingScenario, Boolean includeExamples) in ...\ReportTestData.cs
9999

100100

TestStack.BDDfy.Tests/Reporters/TextReporter/TextReporterTests.ShouldProduceExpectedMarkdownWithExamples.approved.txt renamed to TestStack.BDDfy.Tests/Reporters/TextReporter/TextReporterTests.ShouldProduceExpectedTextWithExamples.approved.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ Scenario: Example Scenario
2525
Then money <action> dispensed
2626

2727
Examples:
28-
| sign | action | Result | Errors |
29-
| positive | is | Passed | |
30-
| negative | is not | Failed | Step: Then money <action> dispensed failed with exception: [Boom] [Details at 1 below] |
28+
| sign | action | Result | Errors |
29+
| positive | is | Passed | |
30+
| negative | is not | Failed | Step: Then money <action> dispensed failed with exception: [Boom With New lines] [Details at 1 below] |
3131

3232
Exceptions:
33-
1. Boom
33+
1. Boom With New lines
3434
at TestStack.BDDfy.Tests.Reporters.ReportTestData.GetScenarios(Boolean includeFailingScenario, Boolean includeExamples) in ...\ReportTestData.cs
3535

3636

TestStack.BDDfy.Tests/Reporters/TextReporter/TextReporterTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public void ShouldProduceExpectedReport()
2929

3030
[Test]
3131
[MethodImpl(MethodImplOptions.NoInlining)]
32-
public void ShouldProduceExpectedMarkdownWithExamples()
32+
public void ShouldProduceExpectedTextWithExamples()
3333
{
3434
var stories = new ReportTestData().CreateTwoStoriesEachWithOneFailingScenarioAndOnePassingScenarioWithThreeStepsOfFiveMillisecondsAndEachHasTwoExamples();
3535
var actual = new StringBuilder();

TestStack.BDDfy.Tests/TestStack.BDDfy.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@
175175
<Content Include="Reporters\Html\MetroReportBuilderTests.ShouldProduceExpectedHtmlWithExamples.approved.txt" />
176176
<Content Include="Reporters\MarkDown\MarkDownReportBuilderTests.ShouldProduceExpectedMarkdown.approved.txt" />
177177
<Content Include="Reporters\MarkDown\MarkDownReportBuilderTests.ShouldProduceExpectedMarkdownWithExamples.approved.txt" />
178-
<Content Include="Reporters\TextReporter\TextReporterTests.ShouldProduceExpectedMarkdownWithExamples.approved.txt" />
178+
<Content Include="Reporters\TextReporter\TextReporterTests.ShouldProduceExpectedTextWithExamples.approved.txt" />
179179
<Content Include="Reporters\TextReporter\TextReporterTests.ShouldProduceExpectedReport.approved.txt" />
180180
</ItemGroup>
181181
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />

TestStack.BDDfy/Reporters/MarkDown/MarkDownReportBuilder.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -171,11 +171,10 @@ void ReportExceptions(StringBuilder report)
171171

172172
static string FlattenExceptionMessage(string message)
173173
{
174-
return message
174+
return string.Join(" ", message
175175
.Replace("\t", " ") // replace tab with one space
176-
.Replace(Environment.NewLine, ", ") // replace new line with one space
177-
.Trim() // trim starting and trailing spaces
178-
.Replace(" ", " ")
176+
.Split(new[] { "\r\n", "\n" }, StringSplitOptions.None)
177+
.Select(s => s.Trim()))
179178
.TrimEnd(','); // chop any , from the end
180179
}
181180
}

TestStack.BDDfy/Reporters/TextReporter.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -211,11 +211,10 @@ void ReportExceptions()
211211

212212
static string FlattenExceptionMessage(string message)
213213
{
214-
return message
214+
return string.Join(" ", message
215215
.Replace("\t", " ") // replace tab with one space
216-
.Replace(Environment.NewLine, ", ") // replace new line with one space
217-
.Trim() // trim starting and trailing spaces
218-
.Replace(" ", " ")
216+
.Split(new[]{"\r\n", "\n"}, StringSplitOptions.None)
217+
.Select(s => s.Trim()))
219218
.TrimEnd(','); // chop any , from the end
220219
}
221220

0 commit comments

Comments
 (0)