Skip to content

Commit bd45374

Browse files
committed
Merge pull request #106 from mwhelan/master
Made story title prefix customisable.
2 parents 6fb64e3 + 99056d7 commit bd45374

17 files changed

Lines changed: 98 additions & 111 deletions

TestStack.BDDfy.Tests/Reporters/Html/HtmlReportBuilderTests.ShouldProduceExpectedHtml.approved.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ body{max-width:100%;background-color:#fff;font-family:Verdana,Arial,Helvetica,sa
7070
<li>
7171
<div class='story NotExecuted'>
7272
<div class='storyMetadata'>
73-
<div class='storyTitle'>Account holder withdraws cash</div>
73+
<div class='storyTitle'>Story: Account holder withdraws cash</div>
7474
<ul class='storyNarrative'>
7575
<li>As an account holder</li>
7676
<li>I want to withdraw cash</li>
@@ -112,7 +112,7 @@ body{max-width:100%;background-color:#fff;font-family:Verdana,Arial,Helvetica,sa
112112
<li>
113113
<div class='story NotExecuted'>
114114
<div class='storyMetadata'>
115-
<div class='storyTitle'>Happiness</div>
115+
<div class='storyTitle'>Story: Happiness</div>
116116
<ul class='storyNarrative'>
117117
<li>As a person</li>
118118
<li>I want ice cream</li>

TestStack.BDDfy.Tests/Reporters/Html/HtmlReportBuilderTests.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
using System;
2-
using System.IO;
3-
using System.Reflection;
42
using System.Runtime.CompilerServices;
5-
using System.Text.RegularExpressions;
63
using ApprovalTests;
74
using ApprovalTests.Reporters;
85
using NUnit.Framework;
@@ -29,8 +26,9 @@ public void ShouldProduceExpectedHtml()
2926
var model = new HtmlReportViewModel(
3027
new DefaultHtmlReportConfiguration(),
3128
new ReportTestData().CreateTwoStoriesEachWithTwoScenariosWithThreeStepsOfFiveMilliseconds());
29+
model.RunDate = new DateTime(2014, 3, 25, 11, 30, 5);
3230

33-
var sut = new HtmlReportBuilder {DateProvider = () => new DateTime(2014, 3, 25, 11, 30, 5)};
31+
var sut = new HtmlReportBuilder();
3432
var result = sut.CreateReport(model);
3533
Approvals.Verify(result);
3634
}

TestStack.BDDfy.Tests/Reporters/HtmlMetro/HtmlMetroReportBuilderTests.ShouldProduceExpectedHtml.approved.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787
<li>
8888
<div class='story Failed'>
8989
<div class='storyMetaData'>
90-
<h3 class='storyTitle'>Account holder withdraws cash</h3>
90+
<h3 class='storyTitle'>Story: Account holder withdraws cash</h3>
9191
<ul class='storyNarrative'>
9292
<li>As an account holder</li>
9393
<li>I want to withdraw cash</li>
@@ -157,7 +157,7 @@
157157
<li>
158158
<div class='story Failed'>
159159
<div class='storyMetaData'>
160-
<h3 class='storyTitle'>Happiness</h3>
160+
<h3 class='storyTitle'>Story: Happiness</h3>
161161
<ul class='storyNarrative'>
162162
<li>As a person</li>
163163
<li>I want ice cream</li>

TestStack.BDDfy.Tests/Reporters/HtmlMetro/HtmlMetroReportBuilderTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@ public void ShouldProduceExpectedHtml()
2828
var model = new HtmlReportViewModel(
2929
new DefaultHtmlReportConfiguration(),
3030
new ReportTestData().CreateMixContainingEachTypeOfOutcome());
31+
model.RunDate = new DateTime(2014, 3, 25, 11, 30, 5);
3132

32-
var sut = new HtmlMetroReportBuilder {DateProvider = () => new DateTime(2014, 3, 25, 11, 30, 5)};
33+
var sut = new HtmlMetroReportBuilder();
3334
var result = sut.CreateReport(model);
3435
Approvals.Verify(result);
3536
}

TestStack.BDDfy.Tests/Stories/StoryClassBase.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@ namespace TestStack.BDDfy.Tests.Stories
22
{
33
[Story(
44
Title = StoryTitle,
5+
TitlePrefix = StoryTitlePrefix,
56
AsA = "As a programmer",
67
IWant = "I want BDDfy to inherit StoryAttribute",
78
SoThat = "So that I can put some shared logic on a base story class")]
89
public abstract class StoryClassBase
910
{
1011
protected const string StoryTitle = "Story base class";
12+
protected const string StoryTitlePrefix = "Specifications: ";
1113

1214
protected void GivenTheStoryAttributeIsSetOnTheBaseClass()
1315
{

TestStack.BDDfy.Tests/Stories/StorySubclass.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ public void Verify()
1212
_story = this.BDDfy();
1313
Assert.That(_story.Metadata, Is.Not.Null);
1414
Assert.That(_story.Metadata.Title, Is.EqualTo(StoryTitle));
15+
Assert.That(_story.Metadata.TitlePrefix, Is.EqualTo(StoryTitlePrefix));
1516
}
1617

1718
void WhenTheSubclassIsBddified()

TestStack.BDDfy/Reporters/ConsoleReporter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ private static void ReportStoryHeader(Story story)
3737
if (story.Metadata == null || story.Metadata.Type == null)
3838
return;
3939

40-
Console.WriteLine("Story: " + story.Metadata.Title);
40+
Console.WriteLine(story.Metadata.TitlePrefix + story.Metadata.Title);
4141
if (!string.IsNullOrEmpty(story.Metadata.Narrative1))
4242
Console.WriteLine("\t" + story.Metadata.Narrative1);
4343
if (!string.IsNullOrEmpty(story.Metadata.Narrative2))

TestStack.BDDfy/Reporters/FileReportModel.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Collections.Generic;
1+
using System;
2+
using System.Collections.Generic;
23
using System.Linq;
34

45
namespace TestStack.BDDfy.Reporters
@@ -9,10 +10,12 @@ public FileReportModel(IEnumerable<Story> stories)
910
{
1011
_stories = stories;
1112
Summary = new FileReportSummaryModel(stories);
13+
RunDate = DateTime.Now;
1214
}
1315

1416
readonly IEnumerable<Story> _stories;
1517
public FileReportSummaryModel Summary { get; private set; }
18+
public DateTime RunDate { get; set; }
1619

1720
public IEnumerable<Story> Stories
1821
{

TestStack.BDDfy/Reporters/Html/BDDfy.css

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -209,10 +209,6 @@ div.story {
209209
border-radius: 10px;
210210
}
211211

212-
.storyTitle:before {
213-
content: "Story: ";
214-
}
215-
216212
.storyTitle {
217213
display: inline;
218214
}

TestStack.BDDfy/Reporters/Html/HtmlReportBuilder.cs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ namespace TestStack.BDDfy.Reporters.Html
66
{
77
public class HtmlReportBuilder : IReportBuilder
88
{
9-
private Func<DateTime> _dateProvider = () => DateTime.Now;
109
private HtmlReportViewModel _viewModel;
1110
readonly StringBuilder _html;
1211
const int TabIndentation = 2;
@@ -43,7 +42,7 @@ private void HtmlHead()
4342
EmbedCssFile(HtmlReportResources.BDDfy_css_min);
4443
EmbedCssFile(_viewModel.CustomStylesheet, HtmlReportResources.CustomStylesheetComment);
4544

46-
AddLine(string.Format("<title>BDDfy Test Result {0}</title>", DateProvider().ToShortDateString()));
45+
AddLine(string.Format("<title>BDDfy Test Result {0}</title>", _viewModel.RunDate.ToShortDateString()));
4746
}
4847
}
4948

@@ -129,7 +128,7 @@ private void ResultDetails()
129128
}
130129
}
131130

132-
AddLine(string.Format("<p><span>Tested at: {0}</span></p>", _dateProvider()));
131+
AddLine(string.Format("<p><span>Tested at: {0}</span></p>", _viewModel.RunDate));
133132
}
134133
}
135134

@@ -226,7 +225,7 @@ private void AddStoryMetadataAndNarrative(Story story)
226225
}
227226
else
228227
{
229-
AddLine(string.Format("<div class='storyTitle'>{0}</div>", story.Metadata.Title));
228+
AddLine(string.Format("<div class='storyTitle'>{0}{1}</div>", story.Metadata.TitlePrefix, story.Metadata.Title));
230229
}
231230

232231
if (story.Metadata != null && !string.IsNullOrEmpty(story.Metadata.Narrative1))
@@ -296,11 +295,5 @@ private void AddHtmlComment(string htmlComment)
296295
_html.AppendFormat("/*{0}*/", htmlComment);
297296
_html.AppendLine();
298297
}
299-
300-
public Func<DateTime> DateProvider
301-
{
302-
get { return _dateProvider; }
303-
set { _dateProvider = value; }
304-
}
305298
}
306299
}

0 commit comments

Comments
 (0)