Skip to content

Commit

Permalink
x97mdr#14 Corrected a bug causing parser to only give a single scenar…
Browse files Browse the repository at this point in the history
…io to a feature even if the feature has more than one scenario
  • Loading branch information
Jeffrey Cameron committed Oct 21, 2011
1 parent 5c43134 commit 08f2379
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 8 deletions.
84 changes: 84 additions & 0 deletions src/Pickles/Pickles.Test/WhenParsingFeatureFiles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,90 @@ When it runs
Assert.AreEqual(null, thenStep.TableArgument);
}

[Test]
public void Then_can_parse_feature_with_multiple_scenarios_successfully()
{
string featureText = @"# ignore this comment
Feature: Test
In order to do something
As a user
I want to run this scenario
Scenario: A scenario
Given some feature
When it runs
Then I should see that this thing happens
Scenario: Another scenario
Given some other feature
When it runs
Then I should see that this other thing happens
And something else";

var parser = new FeatureParser();
var feature = parser.Parse(new StringReader(featureText));

Assert.AreNotEqual(null, feature);
Assert.AreEqual("Test", feature.Name);
Assert.AreEqual(" In order to do something\r\n As a user\r\n I want to run this scenario", feature.Description);
Assert.AreEqual(2, feature.Scenarios.Count);
Assert.AreEqual(0, feature.Tags.Count);

var scenario = feature.Scenarios[0];
Assert.AreEqual("A scenario", scenario.Name);
Assert.AreEqual(string.Empty, scenario.Description);
Assert.AreEqual(3, scenario.Steps.Count);
Assert.AreEqual(0, scenario.Tags.Count);

var givenStep = scenario.Steps[0];
Assert.AreEqual(Keyword.Given, givenStep.Keyword);
Assert.AreEqual("some feature", givenStep.Name);
Assert.AreEqual(null, givenStep.DocStringArgument);
Assert.AreEqual(null, givenStep.TableArgument);

var whenStep = scenario.Steps[1];
Assert.AreEqual(Keyword.When, whenStep.Keyword);
Assert.AreEqual("it runs", whenStep.Name);
Assert.AreEqual(null, whenStep.DocStringArgument);
Assert.AreEqual(null, whenStep.TableArgument);

var thenStep = scenario.Steps[2];
Assert.AreEqual(Keyword.Then, thenStep.Keyword);
Assert.AreEqual("I should see that this thing happens", thenStep.Name);
Assert.AreEqual(null, thenStep.DocStringArgument);
Assert.AreEqual(null, thenStep.TableArgument);

var scenario2 = feature.Scenarios[1];
Assert.AreEqual("Another scenario", scenario2.Name);
Assert.AreEqual(string.Empty, scenario2.Description);
Assert.AreEqual(4, scenario2.Steps.Count);
Assert.AreEqual(0, scenario2.Tags.Count);

var givenStep2 = scenario2.Steps[0];
Assert.AreEqual(Keyword.Given, givenStep2.Keyword);
Assert.AreEqual("some other feature", givenStep2.Name);
Assert.AreEqual(null, givenStep2.DocStringArgument);
Assert.AreEqual(null, givenStep2.TableArgument);

var whenStep2 = scenario2.Steps[1];
Assert.AreEqual(Keyword.When, whenStep2.Keyword);
Assert.AreEqual("it runs", whenStep2.Name);
Assert.AreEqual(null, whenStep2.DocStringArgument);
Assert.AreEqual(null, whenStep2.TableArgument);

var thenStep2 = scenario2.Steps[2];
Assert.AreEqual(Keyword.Then, thenStep2.Keyword);
Assert.AreEqual("I should see that this other thing happens", thenStep2.Name);
Assert.AreEqual(null, thenStep2.DocStringArgument);
Assert.AreEqual(null, thenStep2.TableArgument);

var thenStep3 = scenario2.Steps[3];
Assert.AreEqual(Keyword.And, thenStep3.Keyword);
Assert.AreEqual("something else", thenStep3.Name);
Assert.AreEqual(null, thenStep3.DocStringArgument);
Assert.AreEqual(null, thenStep3.TableArgument);
}

[Test]
public void Then_can_parse_scenario_with_table_successfully()
{
Expand Down
25 changes: 19 additions & 6 deletions src/Pickles/Pickles/Parser/PicklesParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,28 @@ private void AddStepToElement(Step step)
}
}

private void FinalizeBackground()
private void CaptureAndStoreRemainingElements()
{
if (this.featureElementState.IsBackgroundActive)
{
this.backgroundBuilder.AddStep(this.stepBuilder.GetResult());
this.theFeature.Background = this.backgroundBuilder.GetResult();
}
else if (this.featureElementState.IsScenarioActive)
{
if (this.stepBuilder != null) this.scenarioBuilder.AddStep(this.stepBuilder.GetResult());
this.theFeature.AddScenario(this.scenarioBuilder.GetResult());
}
else if (this.featureElementState.IsScenarioOutlineActive)
{
if (this.stepBuilder != null) this.scenarioOutlineBuilder.AddStep(this.stepBuilder.GetResult());
this.theFeature.AddScenarioOutline(this.scenarioOutlineBuilder.GetResult());
}

this.stepBuilder = null;
this.scenarioBuilder = null;
this.scenarioOutlineBuilder = null;
this.backgroundBuilder = null;
}

#region Listener Members
Expand Down Expand Up @@ -97,7 +112,7 @@ public void background(string keyword, string name, string description, int line

public void scenario(string keyword, string name, string description, int line)
{
FinalizeBackground();
CaptureAndStoreRemainingElements();

this.isInExample = false;
this.featureElementState.SetScenarioActive();
Expand All @@ -110,7 +125,7 @@ public void scenario(string keyword, string name, string description, int line)

public void scenarioOutline(string keyword, string name, string description, int line)
{
FinalizeBackground();
CaptureAndStoreRemainingElements();

this.isInExample = false;
this.featureElementState.SetScenarioOutlineActive();
Expand Down Expand Up @@ -157,9 +172,7 @@ public void docString(string contentType, string content, int line)

public void eof()
{
if (this.stepBuilder != null) AddStepToElement(this.stepBuilder.GetResult());
if (this.featureElementState.IsScenarioActive) this.theFeature.AddScenario(this.scenarioBuilder.GetResult());
if (this.featureElementState.IsScenarioOutlineActive) this.theFeature.AddScenarioOutline(this.scenarioOutlineBuilder.GetResult());
CaptureAndStoreRemainingElements();
}

#endregion
Expand Down
4 changes: 2 additions & 2 deletions src/Pickles/VersionInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
using System.Reflection;
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyVersion("0.1.0.0")]
[assembly: AssemblyFileVersion("0.1.0.0")]

0 comments on commit 08f2379

Please sign in to comment.