Skip to content

Commit

Permalink
Gherkin6 Scenario with Examples should be treated as a Scenario… (#1773)
Browse files Browse the repository at this point in the history
* Add test to demonstrate how the Scenario keyword can be used to define a Scenario Outline in Gherkin 6

* fix: A scenario with an "Examples" block should be treated as a Scenario Outline according to Gherkin v6

* Update unit tests to reflect changed behavior
  • Loading branch information
gasparnagy authored and SabotageAndi committed Nov 11, 2019
1 parent f6f5718 commit 7e67c14
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 18 deletions.
10 changes: 1 addition & 9 deletions TechTalk.SpecFlow.Parser/SpecFlowGherkinParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,8 @@ protected override Feature CreateFeature(Tag[] tags, Location location, string l
protected override Scenario CreateScenario(Tag[] tags, Location location, string keyword, string name, string description, Step[] steps, Examples[] examples, AstNode node)
{
ResetBlock();
var token = node.GetItems<AstNode>(RuleType.Scenario).Single().GetItems<Token>(RuleType._ScenarioLine).Single();


if (token.MatchedGherkinDialect.ScenarioOutlineKeywords.Contains(keyword))
if (examples != null && examples.Length > 0)
{
return new ScenarioOutline(tags, location, keyword, name, description, steps, examples);
}
Expand Down Expand Up @@ -99,12 +97,6 @@ protected override GherkinDocument CreateGherkinDocument(Feature feature, Commen
return new SpecFlowDocument((SpecFlowFeature)feature, gherkinDocumentComments, sourceFilePath);
}

//protected override ScenarioOutline CreateScenarioOutline(Tag[] tags, Location location, string keyword, string name, string description, Step[] steps, Examples[] examples, AstNode node)
//{
// ResetBlock();
// return base.CreateScenarioOutline(tags, location, keyword, name, description, steps, examples, node);
//}

protected override Background CreateBackground(Location location, string keyword, string name, string description, Step[] steps, AstNode node)
{
ResetBlock();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@ namespace TechTalk.SpecFlow.GeneratorTests
public class ScenarioOutlineParserTests
{
[Fact]
public void Parser_throws_meaningful_exception_when_Examples_are_missing_in_Scenario_Outline()
public void Parser_doesnt_throw_exception_when_Examples_are_missing_in_Scenario_Outline()
{
// this is accepted by Gherkin v6 and treated as Scenario
var feature = @"Feature: Missing
Scenario Outline: No Examples";

var parser = new SpecFlowGherkinParser(CultureInfo.GetCultureInfo("en"));

Action act = () => parser.Parse(new StringReader(feature), null);

act.Should().Throw<SemanticParserException>().WithMessage("(2:29): Scenario Outline 'No Examples' has no examples defined")
.And.Location.Line.Should().Be(2);
act.Should().NotThrow();
}

[Fact]
Expand Down Expand Up @@ -63,8 +63,9 @@ Given something
}

[Fact]
public void Parser_throws_meaningful_exception_when_Examples_are_missing_in_multiple_Scenario_Outlines()
public void Parser_doesnt_throw_exception_when_Examples_are_missing_in_multiple_Scenario_Outlines()
{
// these are accepted by Gherkin v6 and treated as Scenarios
var feature = @"Feature: Missing
Scenario Outline: No Examples
Scenario Outline: Still no Examples";
Expand All @@ -73,10 +74,7 @@ public void Parser_throws_meaningful_exception_when_Examples_are_missing_in_mult

Action act = () => parser.Parse(new StringReader(feature), null);

var expectedErrors = new List<SemanticParserException> { new SemanticParserException("Scenario Outline 'No Examples' has no examples defined", new Location(2, 29)),
new SemanticParserException("Scenario Outline 'Still no Examples' has no examples defined", new Location(3, 29))};

act.Should().Throw<CompositeParserException>().And.Errors.Should().BeEquivalentTo(expectedErrors);
act.Should().NotThrow();
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Scenario Outline: Should handle scenario outlines
Given there is a SpecFlow project
And row testing is <row test>
Given there is a feature file in the project as
And there is a feature file in the project as
"""
Feature: Simple Feature
Scenario Outline: Simple Scenario Outline
Expand All @@ -25,3 +25,26 @@ Examples:
| case | row test |
| Normal testing | disabled |
| Row testing | enabled |

@gherkin6
Scenario: Should support defining scenario outlines with the Scenario keyword
A scenario with an "Examples" block should be treated as a Scenario Outline according to Gherkin v6
See https://github.com/cucumber/cucumber/blob/master/gherkin/CHANGELOG.md#6013---2018-09-25
Given there is a SpecFlow project
And there is a feature file in the project as
"""
Feature: Simple Feature
Scenario: Simple Scenario Outline
Given there is something
When I do <what>
Then something should happen
Examples:
| what |
| something |
| something else |
"""
And all steps are bound and pass
When I execute the tests
Then the execution summary should contain
| Succeeded |
| 2 |
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Fixes:
+ Adjust parameter names generation in scenario outlines https://github.com/techtalk/SpecFlow/issues/1694
+ specflow.json can be used in SpecFlow+Runner with Process test thread isolation https://github.com/techtalk/SpecFlow/issues/1761
+ specflow.json is copied to output directory automatically https://github.com/techtalk/SpecFlow/issues/1315
+ A scenario with an "Examples" block should be treated as a Scenario Outline according to Gherkin v6
+ step definition method with "object" parameter type might not match


Expand Down

0 comments on commit 7e67c14

Please sign in to comment.