Skip to content

Commit e800a54

Browse files
committed
[Gherkin Vintage] Exclude background from pickle tree
1 parent ac38546 commit e800a54

File tree

8 files changed

+53
-4
lines changed

8 files changed

+53
-4
lines changed

gherkin-messages/src/main/java/io/cucumber/core/gherkin/messages/GherkinMessagesFeature.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public Pickle getPickleAt(Located located) {
6767
return pickles.stream()
6868
.filter(pickle -> pickle.getLocation().equals(location))
6969
.findFirst()
70-
.orElseThrow(() -> new NoSuchElementException("No pickle at " + location));
70+
.orElseThrow(() -> new NoSuchElementException("No pickle in " + uri + " at " + location));
7171
}
7272

7373
@Override

gherkin-messages/src/main/java/io/cucumber/core/gherkin/messages/GherkinMessagesLocation.java

+8
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,12 @@ public int getColumn() {
4242
public int hashCode() {
4343
return Objects.hash(line, column);
4444
}
45+
46+
@Override
47+
public String toString() {
48+
return "Location{" +
49+
"line=" + line +
50+
", column=" + column +
51+
'}';
52+
}
4553
}

gherkin-vintage/src/main/java/io/cucumber/core/gherkin/vintage/GherkinVintageFeature.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package io.cucumber.core.gherkin.vintage;
22

33
import gherkin.ast.GherkinDocument;
4+
import gherkin.ast.Scenario;
45
import gherkin.ast.ScenarioOutline;
56
import io.cucumber.core.gherkin.Feature;
67
import io.cucumber.core.gherkin.Located;
@@ -28,6 +29,9 @@ final class GherkinVintageFeature implements Feature {
2829
this.gherkinSource = gherkinSource;
2930
this.pickles = pickles;
3031
this.children = gherkinDocument.getFeature().getChildren().stream()
32+
.filter(scenarioDefinition ->
33+
(scenarioDefinition instanceof ScenarioOutline)
34+
|| (scenarioDefinition instanceof Scenario))
3135
.map(scenarioDefinition -> {
3236
if (scenarioDefinition instanceof ScenarioOutline) {
3337
ScenarioOutline outline = (ScenarioOutline) scenarioDefinition;
@@ -54,7 +58,7 @@ public Pickle getPickleAt(Located located) {
5458
return pickles.stream()
5559
.filter(pickle -> pickle.getLocation().equals(location))
5660
.findFirst()
57-
.orElseThrow(() -> new NoSuchElementException("No pickle at " + location));
61+
.orElseThrow(() -> new NoSuchElementException("No pickle in " + uri + " at " + location));
5862
}
5963

6064
@Override

gherkin-vintage/src/main/java/io/cucumber/core/gherkin/vintage/GherkinVintageLocation.java

+8
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,12 @@ public int getColumn() {
4646
public int hashCode() {
4747
return Objects.hash(line, column);
4848
}
49+
50+
@Override
51+
public String toString() {
52+
return "Location{" +
53+
"line=" + line +
54+
", column=" + column +
55+
'}';
56+
}
4957
}

gherkin-vintage/src/test/java/io/cucumber/core/gherkin/vintage/FeatureParserTest.java

+15
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,21 @@
1919
class FeatureParserTest {
2020

2121
private final GherkinVintageFeatureParser parser = new GherkinVintageFeatureParser();
22+
@Test
23+
void can_parse_single_scenario() throws IOException {
24+
URI uri = URI.create("classpath:com/example.feature");
25+
String source = new String(readAllBytes(Paths.get("src/test/resources/io/cucumber/core/gherkin/vintage/single.feature")));
26+
Optional<Feature> feature = parser.parse(uri, source, UUID::randomUUID);
27+
assertEquals(1, feature.get().getPickles().size());
28+
}
29+
30+
@Test
31+
void background_elements_are_not_scenarios() throws IOException {
32+
URI uri = URI.create("classpath:com/example.feature");
33+
String source = new String(readAllBytes(Paths.get("src/test/resources/io/cucumber/core/gherkin/vintage/background.feature")));
34+
Optional<Feature> feature = parser.parse(uri, source, UUID::randomUUID);
35+
assertEquals(1, feature.get().getPickles().size());
36+
}
2237

2338
@Test
2439
void empty_feature_file_is_parsed_but_produces_no_feature() throws IOException {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Feature: A feature with a background
2+
3+
Background: A background
4+
Given a single scenario
5+
6+
Scenario: A single scenario
7+
When it is executed
8+
Then nothing else happens
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Feature: A feature with a background
2+
3+
Background: A background
4+
Given a single scenario
5+
6+
Scenario: A single scenario
7+
When it is executed
8+
Then nothing else happens

junit-platform-engine/src/test/java/io/cucumber/junit/platform/engine/FeatureResolverTest.java

-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
import org.junit.jupiter.api.BeforeEach;
44
import org.junit.jupiter.api.Test;
5-
import org.junit.platform.engine.ConfigurationParameters;
6-
import org.junit.platform.engine.EngineDiscoveryRequest;
75
import org.junit.platform.engine.TestDescriptor;
86
import org.junit.platform.engine.TestTag;
97
import org.junit.platform.engine.UniqueId;

0 commit comments

Comments
 (0)