Search in sources :

Example 1 with ScenarioOutline

use of gherkin.formatter.model.ScenarioOutline in project cucumber-jvm by cucumber.

the class CucumberExamplesTest method should_create_example_scenarios.

@Test
public void should_create_example_scenarios() {
    CucumberFeature cucumberFeature = new CucumberFeature(new Feature(COMMENTS, FEATURE_TAGS, "Feature", "", "", 2, "fid"), "f.feature");
    ScenarioOutline so = new ScenarioOutline(COMMENTS, SO_TAGS, "Scenario Outline", "", "", 4, "");
    CucumberScenarioOutline cso = new CucumberScenarioOutline(cucumberFeature, null, so);
    cso.step(new Step(COMMENTS, "Given ", "I have 5 <what> in my <where>", 5, null, null));
    Examples examples = new Examples(COMMENTS, E_TAGS, "Examples", "", "", 6, "", asList(new ExamplesTableRow(COMMENTS, asList("what", "where"), 7, ""), new ExamplesTableRow(COMMENTS, asList("cukes", "belly"), 8, ""), new ExamplesTableRow(COMMENTS, asList("apples", "basket"), 9, "")));
    CucumberExamples cucumberExamples = new CucumberExamples(cso, examples);
    List<CucumberScenario> exampleScenarios = cucumberExamples.createExampleScenarios();
    assertEquals(2, exampleScenarios.size());
    Set<Tag> expectedTags = new HashSet<Tag>();
    expectedTags.addAll(FEATURE_TAGS);
    expectedTags.addAll(SO_TAGS);
    expectedTags.addAll(E_TAGS);
    assertEquals(expectedTags, exampleScenarios.get(0).tagsAndInheritedTags());
    CucumberScenario cucumberScenario = exampleScenarios.get(0);
    Step step = cucumberScenario.getSteps().get(0);
    assertEquals("I have 5 cukes in my belly", step.getName());
}
Also used : Step(gherkin.formatter.model.Step) Feature(gherkin.formatter.model.Feature) ExamplesTableRow(gherkin.formatter.model.ExamplesTableRow) ScenarioOutline(gherkin.formatter.model.ScenarioOutline) Tag(gherkin.formatter.model.Tag) Examples(gherkin.formatter.model.Examples) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 2 with ScenarioOutline

use of gherkin.formatter.model.ScenarioOutline in project cucumber-jvm by cucumber.

the class JUnitReporterTest method forward_calls_to_formatter_interface_methods.

@Test
public void forward_calls_to_formatter_interface_methods() throws Exception {
    String uri = "uri";
    Feature feature = mock(Feature.class);
    Background background = mock(Background.class);
    ScenarioOutline scenarioOutline = mock(ScenarioOutline.class);
    Examples examples = mock(Examples.class);
    Scenario scenario = mock(Scenario.class);
    Step step = mock(Step.class);
    Formatter formatter = mock(Formatter.class);
    jUnitReporter = new JUnitReporter(mock(Reporter.class), formatter, false, new JUnitOptions(Collections.<String>emptyList()));
    jUnitReporter.uri(uri);
    jUnitReporter.feature(feature);
    jUnitReporter.scenarioOutline(scenarioOutline);
    jUnitReporter.examples(examples);
    jUnitReporter.startOfScenarioLifeCycle(scenario);
    jUnitReporter.background(background);
    jUnitReporter.scenario(scenario);
    jUnitReporter.step(step);
    jUnitReporter.endOfScenarioLifeCycle(scenario);
    jUnitReporter.eof();
    jUnitReporter.done();
    jUnitReporter.close();
    verify(formatter).uri(uri);
    verify(formatter).feature(feature);
    verify(formatter).scenarioOutline(scenarioOutline);
    verify(formatter).examples(examples);
    verify(formatter).startOfScenarioLifeCycle(scenario);
    ;
    verify(formatter).background(background);
    verify(formatter).scenario(scenario);
    verify(formatter).step(step);
    verify(formatter).endOfScenarioLifeCycle(scenario);
    verify(formatter).eof();
    verify(formatter).done();
    verify(formatter).close();
}
Also used : Background(gherkin.formatter.model.Background) ScenarioOutline(gherkin.formatter.model.ScenarioOutline) Formatter(gherkin.formatter.Formatter) Step(gherkin.formatter.model.Step) Feature(gherkin.formatter.model.Feature) Examples(gherkin.formatter.model.Examples) Scenario(gherkin.formatter.model.Scenario) Test(org.junit.Test)

Example 3 with ScenarioOutline

use of gherkin.formatter.model.ScenarioOutline in project cucumber-jvm by cucumber.

the class CucumberScenarioOutlineTest method replaces_tokens_in_scenario_names.

/***
     * From a scenario outline, we create one or more "Example Scenario"s. This is composed
     * of each step from the outline, with the tokens replaced with the pertient values 
     * for the current example row. <p />
     * 
     * Each "Example Scenario" has a name. This was previously just a copy of the outline's
     * name. However, we'd like to be able to support token replacement in the scenario too,
     * for example:
     * 
     * <pre>
     * Scenario Outline: Time offset check for <LOCATION_NAME>
     * Given my local country is <LOCATION_NAME>
     * When I compare the time difference to GMT
     * Then the time offset should be <OFFSET>
     *  
     * Examples: 
     * | LOCATION_NAME | OFFSET |
     * | London        | 1      |
     * | San Fran      | 8      |
     * </pre>
     * 
     * Will create a scenario named "Time offset check for London" for the first row in the 
     * examples table.
     */
@Test
public void replaces_tokens_in_scenario_names() {
    // Create Gherkin the outline itself ...
    ScenarioOutline outline = new ScenarioOutline(C, T, "Scenario Outline", "Time offset check for <LOCATION_NAME>", "", new Integer(1), "");
    // ... then the Cukes implementation
    CucumberScenarioOutline cukeOutline = new CucumberScenarioOutline(null, null, outline);
    CucumberScenario exampleScenario = cukeOutline.createExampleScenario(new ExamplesTableRow(C, asList("LOCATION_NAME"), 1, ""), new ExamplesTableRow(C, asList("London"), 1, ""), T, "");
    assertEquals("Time offset check for London", exampleScenario.getGherkinModel().getName());
}
Also used : ExamplesTableRow(gherkin.formatter.model.ExamplesTableRow) ScenarioOutline(gherkin.formatter.model.ScenarioOutline) Test(org.junit.Test)

Aggregations

ScenarioOutline (gherkin.formatter.model.ScenarioOutline)3 Test (org.junit.Test)3 Examples (gherkin.formatter.model.Examples)2 ExamplesTableRow (gherkin.formatter.model.ExamplesTableRow)2 Feature (gherkin.formatter.model.Feature)2 Step (gherkin.formatter.model.Step)2 Formatter (gherkin.formatter.Formatter)1 Background (gherkin.formatter.model.Background)1 Scenario (gherkin.formatter.model.Scenario)1 Tag (gherkin.formatter.model.Tag)1 HashSet (java.util.HashSet)1