diff --git a/TestStack.BDDfy.Tests/Processors/Reports/MarkDown/MarkDownReporterSpecs.cs b/TestStack.BDDfy.Tests/Processors/Reports/MarkDown/MarkDownReporterSpecs.cs index eb6e771f..e2274518 100644 --- a/TestStack.BDDfy.Tests/Processors/Reports/MarkDown/MarkDownReporterSpecs.cs +++ b/TestStack.BDDfy.Tests/Processors/Reports/MarkDown/MarkDownReporterSpecs.cs @@ -33,8 +33,10 @@ public void ShouldPrintErrorInReportIfProcessingFails() sut.Process(new List()); - _writer.Received().OutputReport("There was an error compiling the markdown report: Error occurred.", - Arg.Any(), Arg.Any()); + _writer.Received().OutputReport( + Arg.Is(s => s.StartsWith("Error occurred.")), + Arg.Any(), + Arg.Any()); } private MarkDownReporter CreateSut() diff --git a/TestStack.BDDfy.Tests/Story/StoryCanBeSpecifiedInReflectiveMode.cs b/TestStack.BDDfy.Tests/Story/StoryCanBeSpecifiedInReflectiveMode.cs index 2dd8bf2c..4fdcd810 100644 --- a/TestStack.BDDfy.Tests/Story/StoryCanBeSpecifiedInReflectiveMode.cs +++ b/TestStack.BDDfy.Tests/Story/StoryCanBeSpecifiedInReflectiveMode.cs @@ -7,7 +7,7 @@ namespace TestStack.BDDfy.Tests.Story public class StoryCanBeSpecifiedInReflectiveMode { [Test] - public void Verift() + public void Verify() { var story = this.BDDfy(); diff --git a/TestStack.BDDfy.Tests/Story/WhenStoryAttibuteMissesAsATextInAsAProperty.cs b/TestStack.BDDfy.Tests/Story/WhenStoryAttibuteMissesAsATextInAsAProperty.cs new file mode 100644 index 00000000..e3e4d16b --- /dev/null +++ b/TestStack.BDDfy.Tests/Story/WhenStoryAttibuteMissesAsATextInAsAProperty.cs @@ -0,0 +1,23 @@ +using NUnit.Framework; +using TestStack.BDDfy.Core; + +namespace TestStack.BDDfy.Tests.Story +{ + [TestFixture] + [Story( + AsA = "programmer", + IWant = "I want the missing 'As a' to be added to story metadata", + SoThat = "So that I don't have to duplicate it on the string")] + public class WhenStoryAttibuteMissesAsATextInAsAProperty + { + [Test] + public void Then_it_is_injected_by_BDDfy() + { + var story = new DummyScenario().BDDfy(); + + Assert.That(story.MetaData.AsA, Is.EqualTo("As a programmer")); + Assert.That(story.MetaData.IWant, Is.EqualTo("I want the missing 'As a' to be added to story metadata")); + Assert.That(story.MetaData.SoThat, Is.EqualTo("So that I don't have to duplicate it on the string")); + } + } +} \ No newline at end of file diff --git a/TestStack.BDDfy.Tests/Story/WhenStoryAttibuteMissesDuplicateTextsInProperties.cs b/TestStack.BDDfy.Tests/Story/WhenStoryAttibuteMissesDuplicateTextsInProperties.cs new file mode 100644 index 00000000..0ca56fd6 --- /dev/null +++ b/TestStack.BDDfy.Tests/Story/WhenStoryAttibuteMissesDuplicateTextsInProperties.cs @@ -0,0 +1,23 @@ +using NUnit.Framework; +using TestStack.BDDfy.Core; + +namespace TestStack.BDDfy.Tests.Story +{ + [TestFixture] + [Story( + AsA = "programmer", + IWant = "the missing texts to be added to story metadata", + SoThat = "I don't have to duplicate it on the string")] + public class WhenStoryAttibuteMissesDuplicateTextsInProperties + { + [Test] + public void Then_it_is_injected_by_BDDfy() + { + var story = new DummyScenario().BDDfy(); + + Assert.That(story.MetaData.AsA, Is.EqualTo("As a programmer")); + Assert.That(story.MetaData.IWant, Is.EqualTo("I want the missing texts to be added to story metadata")); + Assert.That(story.MetaData.SoThat, Is.EqualTo("So that I don't have to duplicate it on the string")); + } + } +} \ No newline at end of file diff --git a/TestStack.BDDfy.Tests/Story/WhenStoryAttibuteMissesIWantTextInIWantProperty.cs b/TestStack.BDDfy.Tests/Story/WhenStoryAttibuteMissesIWantTextInIWantProperty.cs new file mode 100644 index 00000000..ca6a9161 --- /dev/null +++ b/TestStack.BDDfy.Tests/Story/WhenStoryAttibuteMissesIWantTextInIWantProperty.cs @@ -0,0 +1,23 @@ +using NUnit.Framework; +using TestStack.BDDfy.Core; + +namespace TestStack.BDDfy.Tests.Story +{ + [TestFixture] + [Story( + AsA = "As a programmer", + IWant = "the missing 'I want' to be added to story metadata", + SoThat = "So that I don't have to duplicate it on the string")] + public class WhenStoryAttibuteMissesIWantTextInIWantProperty + { + [Test] + public void Then_it_is_injected_by_BDDfy() + { + var story = new DummyScenario().BDDfy(); + + Assert.That(story.MetaData.AsA, Is.EqualTo("As a programmer")); + Assert.That(story.MetaData.IWant, Is.EqualTo("I want the missing 'I want' to be added to story metadata")); + Assert.That(story.MetaData.SoThat, Is.EqualTo("So that I don't have to duplicate it on the string")); + } + } +} \ No newline at end of file diff --git a/TestStack.BDDfy.Tests/Story/WhenStoryAttibuteMissesSoThatTextInSoThatProperty.cs b/TestStack.BDDfy.Tests/Story/WhenStoryAttibuteMissesSoThatTextInSoThatProperty.cs new file mode 100644 index 00000000..36095e20 --- /dev/null +++ b/TestStack.BDDfy.Tests/Story/WhenStoryAttibuteMissesSoThatTextInSoThatProperty.cs @@ -0,0 +1,23 @@ +using NUnit.Framework; +using TestStack.BDDfy.Core; + +namespace TestStack.BDDfy.Tests.Story +{ + [TestFixture] + [Story( + AsA = "As a programmer", + IWant = "I want the missing 'So that' to be added to story metadata", + SoThat = "I don't have to duplicate it on the string")] + public class WhenStoryAttibuteMissesSoThatTextInSoThatProperty + { + [Test] + public void Then_it_is_injected_by_BDDfy() + { + var story = new DummyScenario().BDDfy(); + + Assert.That(story.MetaData.AsA, Is.EqualTo("As a programmer")); + Assert.That(story.MetaData.IWant, Is.EqualTo("I want the missing 'So that' to be added to story metadata")); + Assert.That(story.MetaData.SoThat, Is.EqualTo("So that I don't have to duplicate it on the string")); + } + } +} \ No newline at end of file diff --git a/TestStack.BDDfy.Tests/TestStack.BDDfy.Tests.csproj b/TestStack.BDDfy.Tests/TestStack.BDDfy.Tests.csproj index 303ad651..3922d4c5 100644 --- a/TestStack.BDDfy.Tests/TestStack.BDDfy.Tests.csproj +++ b/TestStack.BDDfy.Tests/TestStack.BDDfy.Tests.csproj @@ -99,6 +99,10 @@ + + + + diff --git a/TestStack.BDDfy/Core/StoryMetaData.cs b/TestStack.BDDfy/Core/StoryMetaData.cs index 3ceab937..561c9e0a 100644 --- a/TestStack.BDDfy/Core/StoryMetaData.cs +++ b/TestStack.BDDfy/Core/StoryMetaData.cs @@ -1,9 +1,16 @@ using System; +using System.Text; namespace TestStack.BDDfy.Core { public class StoryMetaData { + // ReSharper disable InconsistentNaming + private const string I_want_prefix = "I want"; + private const string So_that_prefix = "So that"; + private const string As_a_prefix = "As a"; + // ReSharper restore InconsistentNaming + public StoryMetaData(Type storyType, StoryAttribute storyAttribute) { var title = storyAttribute.Title; @@ -13,9 +20,9 @@ public StoryMetaData(Type storyType, StoryAttribute storyAttribute) Type = storyType; Title = title; - AsA = storyAttribute.AsA; - IWant = storyAttribute.IWant; - SoThat = storyAttribute.SoThat; + AsA = CleanseProperty(storyAttribute.AsA, As_a_prefix); + IWant= CleanseProperty(storyAttribute.IWant, I_want_prefix); + SoThat = CleanseProperty(storyAttribute.SoThat, So_that_prefix); } public StoryMetaData(Type storyType, string asA, string iWant, string soThat, string storyTitle = null) @@ -23,9 +30,23 @@ public StoryMetaData(Type storyType, string asA, string iWant, string soThat, st Title = storyTitle ?? NetToString.Convert(storyType.Name); Type = storyType; - AsA = asA; - IWant = iWant; - SoThat = soThat; + AsA = CleanseProperty(asA, As_a_prefix); + IWant = CleanseProperty(iWant, I_want_prefix); + SoThat = CleanseProperty(soThat, So_that_prefix); + } + + string CleanseProperty(string text, string prefix) + { + var property = new StringBuilder(); + + if (string.IsNullOrWhiteSpace(text)) + return null; + + if (!text.StartsWith(prefix, StringComparison.OrdinalIgnoreCase)) + property.AppendFormat("{0} ", prefix); + + property.Append(text); + return property.ToString(); } public Type Type { get; private set; }