Search in sources :

Example 21 with CucumberFeature

use of cucumber.runtime.model.CucumberFeature in project cucumber-jvm by cucumber.

the class RuntimeTest method should_make_scenario_id_available_to_hooks.

@Test
public void should_make_scenario_id_available_to_hooks() throws Throwable {
    CucumberFeature feature = TestHelper.feature("path/test.feature", "Feature: feature name\n" + "  Scenario: scenario name\n" + "    Given first step\n" + "    When second step\n" + "    Then third step\n");
    HookDefinition beforeHook = mock(HookDefinition.class);
    when(beforeHook.matches(anyCollectionOf(Tag.class))).thenReturn(true);
    Runtime runtime = createRuntimeWithMockedGlue(mock(StepDefinitionMatch.class), beforeHook, true);
    feature.run(mock(Formatter.class), mock(Reporter.class), runtime);
    ArgumentCaptor<Scenario> capturedScenario = ArgumentCaptor.forClass(Scenario.class);
    verify(beforeHook).execute(capturedScenario.capture());
    assertEquals("feature-name;scenario-name", capturedScenario.getValue().getId());
}
Also used : CucumberFeature(cucumber.runtime.model.CucumberFeature) JSONFormatter(gherkin.formatter.JSONFormatter) Formatter(gherkin.formatter.Formatter) CucumberJSONFormatter(cucumber.runtime.formatter.CucumberJSONFormatter) StepDefinitionReporter(cucumber.api.StepDefinitionReporter) Reporter(gherkin.formatter.Reporter) Tag(gherkin.formatter.model.Tag) Scenario(cucumber.api.Scenario) Test(org.junit.Test)

Example 22 with CucumberFeature

use of cucumber.runtime.model.CucumberFeature in project cucumber-jvm by cucumber.

the class RuntimeTest method should_call_formatter_for_two_scenarios_with_background.

@Test
public void should_call_formatter_for_two_scenarios_with_background() throws Throwable {
    CucumberFeature feature = TestHelper.feature("path/test.feature", "" + "Feature: feature name\n" + "  Background: background\n" + "    Given first step\n" + "  Scenario: scenario_1 name\n" + "    When second step\n" + "    Then third step\n" + "  Scenario: scenario_2 name\n" + "    Then second step\n");
    Map<String, Result> stepsToResult = new HashMap<String, Result>();
    stepsToResult.put("first step", result("passed"));
    stepsToResult.put("second step", result("passed"));
    stepsToResult.put("third step", result("passed"));
    String formatterOutput = runFeatureWithFormatterSpy(feature, stepsToResult);
    assertEquals("" + "uri\n" + "feature\n" + "  startOfScenarioLifeCycle\n" + "  background\n" + "    step\n" + "    match\n" + "    result\n" + "  scenario\n" + "    step\n" + "    step\n" + "    match\n" + "    result\n" + "    match\n" + "    result\n" + "  endOfScenarioLifeCycle\n" + "  startOfScenarioLifeCycle\n" + "  background\n" + "    step\n" + "    match\n" + "    result\n" + "  scenario\n" + "    step\n" + "    match\n" + "    result\n" + "  endOfScenarioLifeCycle\n" + "eof\n" + "done\n" + "close\n", formatterOutput);
}
Also used : CucumberFeature(cucumber.runtime.model.CucumberFeature) HashMap(java.util.HashMap) Matchers.anyString(org.mockito.Matchers.anyString) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Result(gherkin.formatter.model.Result) Test(org.junit.Test)

Example 23 with CucumberFeature

use of cucumber.runtime.model.CucumberFeature in project cucumber-jvm by cucumber.

the class RerunFormatterTest method should_leave_report_empty_when_exit_code_is_zero.

@Test
public void should_leave_report_empty_when_exit_code_is_zero() throws Throwable {
    CucumberFeature feature = TestHelper.feature("path/test.feature", "" + "Feature: feature name\n" + "  Scenario: passed scenario\n" + "    Given passed step\n" + "  Scenario: pending scenario\n" + "    Given pending step\n" + "  Scenario: undefined scenario\n" + "    Given undefined step\n");
    Map<String, Result> stepsToResult = new HashMap<String, Result>();
    stepsToResult.put("passed step", result("passed"));
    stepsToResult.put("pending step", result("pending"));
    stepsToResult.put("undefined step", result("undefined"));
    String formatterOutput = runFeatureWithRerunFormatter(feature, stepsToResult);
    assertEquals("", formatterOutput);
}
Also used : CucumberFeature(cucumber.runtime.model.CucumberFeature) HashMap(java.util.HashMap) Result(gherkin.formatter.model.Result) Test(org.junit.Test)

Example 24 with CucumberFeature

use of cucumber.runtime.model.CucumberFeature in project cucumber-jvm by cucumber.

the class RerunFormatterTest method should_use_scenario_location_when_background_step_fails.

@Test
public void should_use_scenario_location_when_background_step_fails() throws Throwable {
    CucumberFeature feature = TestHelper.feature("path/test.feature", "" + "Feature: feature name\n" + "  Background: the background\n" + "    Given background step\n" + "  Scenario: scenario name\n" + "    When second step\n" + "    Then third step\n");
    Map<String, Result> stepsToResult = new HashMap<String, Result>();
    stepsToResult.put("background step", result("failed"));
    stepsToResult.put("second step", result("passed"));
    stepsToResult.put("third step", result("passed"));
    String formatterOutput = runFeatureWithRerunFormatter(feature, stepsToResult);
    assertEquals("path/test.feature:4", formatterOutput);
}
Also used : CucumberFeature(cucumber.runtime.model.CucumberFeature) HashMap(java.util.HashMap) Result(gherkin.formatter.model.Result) Test(org.junit.Test)

Example 25 with CucumberFeature

use of cucumber.runtime.model.CucumberFeature in project cucumber-jvm by cucumber.

the class RerunFormatterTest method should_use_scenario_location_when_after_hook_fails.

@Test
public void should_use_scenario_location_when_after_hook_fails() throws Throwable {
    CucumberFeature feature = TestHelper.feature("path/test.feature", "" + "Feature: feature name\n" + "  Scenario: scenario name\n" + "    Given first step\n" + "    When second step\n" + "    Then third step\n");
    Map<String, Result> stepsToResult = new HashMap<String, Result>();
    stepsToResult.put("first step", result("passed"));
    stepsToResult.put("second step", result("passed"));
    stepsToResult.put("third step", result("passed"));
    List<SimpleEntry<String, Result>> hooks = new ArrayList<SimpleEntry<String, Result>>();
    hooks.add(TestHelper.hookEntry("after", result("failed")));
    String formatterOutput = runFeatureWithRerunFormatter(feature, stepsToResult, hooks);
    assertEquals("path/test.feature:2", formatterOutput);
}
Also used : CucumberFeature(cucumber.runtime.model.CucumberFeature) HashMap(java.util.HashMap) SimpleEntry(java.util.AbstractMap.SimpleEntry) ArrayList(java.util.ArrayList) Result(gherkin.formatter.model.Result) Test(org.junit.Test)

Aggregations

CucumberFeature (cucumber.runtime.model.CucumberFeature)64 Test (org.junit.Test)53 HashMap (java.util.HashMap)33 Result (gherkin.formatter.model.Result)32 ArrayList (java.util.ArrayList)19 SimpleEntry (java.util.AbstractMap.SimpleEntry)10 ClasspathResourceLoader (cucumber.runtime.io.ClasspathResourceLoader)6 Resource (cucumber.runtime.io.Resource)6 Formatter (gherkin.formatter.Formatter)5 Reporter (gherkin.formatter.Reporter)5 StepDefinitionReporter (cucumber.api.StepDefinitionReporter)4 Step (gherkin.formatter.model.Step)4 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)4 Matchers.anyString (org.mockito.Matchers.anyString)4 CucumberJSONFormatter (cucumber.runtime.formatter.CucumberJSONFormatter)3 CucumberTagStatement (cucumber.runtime.model.CucumberTagStatement)3 JSONFormatter (gherkin.formatter.JSONFormatter)3 Tag (gherkin.formatter.model.Tag)3 Description (org.junit.runner.Description)3 Scenario (cucumber.api.Scenario)2