Search in sources :

Example 16 with Step

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

the class CucumberScenarioOutlineTest method replaces_tokens_in_doc_strings.

@Test
public void replaces_tokens_in_doc_strings() {
    Step outlineStep = new Step(C, null, "I have <n> cukes", 0, null, new DocString(null, "I have <n> cukes", 1));
    Step exampleStep = CucumberScenarioOutline.createExampleStep(outlineStep, new ExamplesTableRow(C, asList("n"), 1, ""), new ExamplesTableRow(C, asList("10"), 1, ""));
    assertEquals("I have 10 cukes", exampleStep.getDocString().getValue());
}
Also used : ExamplesTableRow(gherkin.formatter.model.ExamplesTableRow) DocString(gherkin.formatter.model.DocString) Step(gherkin.formatter.model.Step) Test(org.junit.Test)

Example 17 with Step

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

the class CucumberScenarioOutlineTest method allows_data_table_entries_to_be_empty_after_replacement.

@Test
public void allows_data_table_entries_to_be_empty_after_replacement() {
    List<DataTableRow> rows = asList(new DataTableRow(C, asList("<entry>"), 1));
    Step outlineStep = new Step(C, null, "Some step", 0, rows, null);
    Step exampleStep = CucumberScenarioOutline.createExampleStep(outlineStep, new ExamplesTableRow(C, asList("entry"), 1, ""), new ExamplesTableRow(C, asList(""), 1, ""));
    assertEquals(asList(""), exampleStep.getRows().get(0).getCells());
}
Also used : ExamplesTableRow(gherkin.formatter.model.ExamplesTableRow) Step(gherkin.formatter.model.Step) DataTableRow(gherkin.formatter.model.DataTableRow) Test(org.junit.Test)

Example 18 with Step

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

the class JavaStepDefinitionTest method does_not_throw_ambiguous_when_nothing_is_ambiguous.

@Test
public void does_not_throw_ambiguous_when_nothing_is_ambiguous() throws Throwable {
    backend.addStepDefinition(THREE_DISABLED_MICE.getAnnotation(Given.class), THREE_DISABLED_MICE);
    Reporter reporter = new Reporter() {

        @Override
        public void before(Match match, Result result) {
            throw new UnsupportedOperationException();
        }

        @Override
        public void result(Result result) {
            if (result.getError() != null) {
                throw new RuntimeException(result.getError());
            }
        }

        @Override
        public void after(Match match, Result result) {
            throw new UnsupportedOperationException();
        }

        @Override
        public void match(Match match) {
        }

        @Override
        public void embedding(String mimeType, byte[] data) {
        }

        @Override
        public void write(String text) {
        }
    };
    runtime.buildBackendWorlds(reporter, Collections.<Tag>emptySet(), mock(Scenario.class));
    Tag tag = new Tag("@foo", 0);
    Set<Tag> tags = asSet(tag);
    runtime.runBeforeHooks(reporter, tags);
    Step step = new Step(NO_COMMENTS, "Given ", "three blind mice", 1, null, null);
    runtime.runStep("some.feature", step, reporter, ENGLISH);
    assertTrue(defs.foo);
    assertFalse(defs.bar);
}
Also used : Given(cucumber.api.java.en.Given) Reporter(gherkin.formatter.Reporter) Tag(gherkin.formatter.model.Tag) Step(gherkin.formatter.model.Step) Match(gherkin.formatter.model.Match) Result(gherkin.formatter.model.Result) Scenario(gherkin.formatter.model.Scenario) Test(org.junit.Test)

Example 19 with Step

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

the class ExecutionUnitRunnerTest method shouldAssignUnequalDescriptionsToDifferentOccurrencesOfSameStepInAScenario.

@Test
public void shouldAssignUnequalDescriptionsToDifferentOccurrencesOfSameStepInAScenario() throws Exception {
    List<CucumberFeature> features = CucumberFeature.load(new ClasspathResourceLoader(this.getClass().getClassLoader()), asList("cucumber/runtime/junit/fb.feature"), Collections.emptyList());
    ExecutionUnitRunner runner = new ExecutionUnitRunner(null, (CucumberScenario) features.get(0).getFeatureElements().get(0), createStandardJUnitReporter());
    // fish out the two occurrences of the same step and check whether we really got them
    Step stepOccurrence1 = runner.getChildren().get(0);
    Step stepOccurrence2 = runner.getChildren().get(2);
    assertEquals(stepOccurrence1.getName(), stepOccurrence2.getName());
    // then check that the descriptions are unequal
    Description runnerDescription = runner.getDescription();
    Description stepDescription1 = runnerDescription.getChildren().get(0);
    Description stepDescription2 = runnerDescription.getChildren().get(2);
    assertFalse("Descriptions must not be equal.", stepDescription1.equals(stepDescription2));
}
Also used : Description(org.junit.runner.Description) CucumberFeature(cucumber.runtime.model.CucumberFeature) ClasspathResourceLoader(cucumber.runtime.io.ClasspathResourceLoader) Step(gherkin.formatter.model.Step) Test(org.junit.Test)

Example 20 with Step

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

the class JUnitReporterTest method throws_exception_when_runner_step_name_do_no_match_scenario_step_name.

@Test
public void throws_exception_when_runner_step_name_do_no_match_scenario_step_name() throws Exception {
    Step runnerStep = mockStep("Runner Step Name");
    ExecutionUnitRunner executionUnitRunner = mockExecutionUnitRunner(runnerSteps(runnerStep));
    jUnitReporter = new JUnitReporter(mock(Reporter.class), mock(Formatter.class), false, new JUnitOptions(Collections.<String>emptyList()));
    jUnitReporter.startExecutionUnit(executionUnitRunner, mock(RunNotifier.class));
    jUnitReporter.startOfScenarioLifeCycle(mock(Scenario.class));
    jUnitReporter.step(mockStep("Scenario Step Name"));
    try {
        jUnitReporter.match(mock(Match.class));
        fail("CucumberException not thrown");
    } catch (CucumberException e) {
        assertEquals("Expected step: \"Scenario Step Name\" got step: \"Runner Step Name\"", e.getMessage());
    } catch (Exception e) {
        fail("CucumberException not thrown");
    }
}
Also used : RunNotifier(org.junit.runner.notification.RunNotifier) Step(gherkin.formatter.model.Step) CucumberException(cucumber.runtime.CucumberException) PendingException(cucumber.api.PendingException) CucumberException(cucumber.runtime.CucumberException) Scenario(gherkin.formatter.model.Scenario) Match(gherkin.formatter.model.Match) Test(org.junit.Test)

Aggregations

Step (gherkin.formatter.model.Step)50 Test (org.junit.Test)34 LocalizedXStreams (cucumber.runtime.xstream.LocalizedXStreams)9 Argument (gherkin.formatter.Argument)9 ExamplesTableRow (gherkin.formatter.model.ExamplesTableRow)7 Scenario (gherkin.formatter.model.Scenario)7 DocString (gherkin.formatter.model.DocString)6 Description (org.junit.runner.Description)6 I18n (gherkin.I18n)5 CucumberFeature (cucumber.runtime.model.CucumberFeature)4 DataTableRow (gherkin.formatter.model.DataTableRow)4 Match (gherkin.formatter.model.Match)4 CucumberException (cucumber.runtime.CucumberException)3 SnippetGenerator (cucumber.runtime.snippets.SnippetGenerator)3 Tag (gherkin.formatter.model.Tag)3 GherkinStep (org.jetbrains.plugins.cucumber.psi.GherkinStep)3 RunNotifier (org.junit.runner.notification.RunNotifier)3 Given (cucumber.api.java.en.Given)2 StepDefinition (cucumber.runtime.StepDefinition)2 StepDefinitionMatch (cucumber.runtime.StepDefinitionMatch)2