CukedoctorFeatureRenderer extends AbstractBaseRenderer implements FeatureRenderer { protected String renderFeatureScenarios(Feature feature, CukedoctorDocumentBuilder builder) { StringBuilder sb = new StringBuilder(); for (Scenario scenario : feature.getScenarios()) { sb.append(renderFeatureScenario(scenario, feature, builder)); } feature.setBackgroundRendered(false); return sb.toString(); } CukedoctorFeatureRenderer();  CukedoctorFeatureRenderer(DocumentAttributes documentAttributes);  CukedoctorFeatureRenderer(CukedoctorConfig cukedoctorConfig); @Override String renderFeature(Feature feature); @Override String renderFeatures(List<Feature> features);  }
@Test public void shouldRenderFeatureScenarios() { final Feature feature = FeatureBuilder.instance().aFeatureWithTwoScenarios(); CukedoctorScenarioRenderer scenarioRenderer = new CukedoctorScenarioRenderer(); scenarioRenderer = spy(scenarioRenderer); doReturn("").when(scenarioRenderer).renderScenarioSteps(anyListOf(Step.class), any(Scenario.class), any(Feature.class)); doReturn("").when(scenarioRenderer).renderScenarioExamples(any(Scenario.class)); doReturn("").when(scenarioRenderer).renderScenarioTags(any(Scenario.class), eq(feature)); CukedoctorFeatureRenderer featureRenderer = new CukedoctorFeatureRenderer(); featureRenderer = spy(featureRenderer); featureRenderer.scenarioRenderer = scenarioRenderer; String resultDoc = featureRenderer.renderFeatureScenarios(feature, new CukedoctorDocumentBuilderImpl().createNestedBuilder().createNestedBuilder()); assertThat(resultDoc).isEqualTo("==== Scenario: scenario 1" + newLine() + "description" + newLine() + newLine() + "==== Scenario: scenario 2" + newLine() + "description 2" + newLine() + newLine()); }
@Test public void shouldRenderFeatureScenariosWithTagsInScenarios() { final Feature feature = FeatureBuilder.instance().aFeatureWithTwoScenarios(); for (Scenario scenario : feature.getScenarios()) { ScenarioBuilder.instance(scenario).tag(new Tag("@Tag1")).tag(new Tag("@tag2")); } CukedoctorScenarioRenderer scenarioRenderer = new CukedoctorScenarioRenderer(); scenarioRenderer = spy(scenarioRenderer); doReturn("").when(scenarioRenderer).renderScenarioSteps(anyListOf(Step.class), any(Scenario.class), any(Feature.class)); doReturn("").when(scenarioRenderer).renderScenarioExamples(any(Scenario.class)); CukedoctorFeatureRenderer featureRenderer = new CukedoctorFeatureRenderer(); featureRenderer = spy(featureRenderer); featureRenderer.scenarioRenderer = scenarioRenderer; String resultDoc = featureRenderer.renderFeatureScenarios(feature, new CukedoctorDocumentBuilderImpl().createNestedBuilder().createNestedBuilder()); assertThat(resultDoc).isEqualTo("==== Scenario: scenario 1" + newLine() + "[small]#tags: @tag2,@Tag1#" + newLine() + "" + newLine() + "description" + newLine() + newLine() + "==== Scenario: scenario 2" + newLine() + "[small]#tags: @tag2,@Tag1#" + newLine() + "" + newLine() + "description 2" + newLine() + newLine()); }
@Test public void shouldRenderFeatureScenariosWithTagsInFeaturesAndScenarios() { final Feature feature = FeatureBuilder.instance().aFeatureWithTwoScenarios(); feature.getTags().add(new Tag("@FeatureTag")); for (Scenario scenario : feature.getScenarios()) { ScenarioBuilder.instance(scenario).tag(new Tag("@Tag1")).tag(new Tag("@tag2")); } CukedoctorScenarioRenderer scenarioRenderer = new CukedoctorScenarioRenderer(); scenarioRenderer = spy(scenarioRenderer); doReturn("").when(scenarioRenderer).renderScenarioSteps(anyListOf(Step.class), any(Scenario.class), any(Feature.class)); doReturn("").when(scenarioRenderer).renderScenarioExamples(any(Scenario.class)); CukedoctorFeatureRenderer featureRenderer = new CukedoctorFeatureRenderer(); featureRenderer = spy(featureRenderer); featureRenderer.scenarioRenderer = scenarioRenderer; String resultDoc = featureRenderer.renderFeatureScenarios(feature, new CukedoctorDocumentBuilderImpl().createNestedBuilder().createNestedBuilder()); assertThat(resultDoc).isEqualTo("==== Scenario: scenario 1" + newLine() + "[small]#tags: @tag2,@FeatureTag,@Tag1#" + newLine() + "" + newLine() + "description" + newLine() + newLine() + "==== Scenario: scenario 2" + newLine() + "[small]#tags: @tag2,@FeatureTag,@Tag1#" + newLine() + "" + newLine() + "description 2" + newLine() + newLine()); }
@Test public void shouldRenderFeatureScenariosOmittingTagsIfOrderFeatureTagIsTheOnlyTag() { final Feature feature = FeatureBuilder.instance().aFeatureWithTwoScenarios(); final String orderTagName = "@order-42"; feature.getTags().add(new Tag(orderTagName)); for (Scenario scenario : feature.getScenarios()) { ScenarioBuilder.instance(scenario).tag(new Tag(orderTagName)); } CukedoctorScenarioRenderer scenarioRenderer = new CukedoctorScenarioRenderer(); scenarioRenderer = spy(scenarioRenderer); doReturn("").when(scenarioRenderer).renderScenarioSteps(anyListOf(Step.class), any(Scenario.class), any(Feature.class)); doReturn("").when(scenarioRenderer).renderScenarioExamples(any(Scenario.class)); CukedoctorFeatureRenderer featureRenderer = new CukedoctorFeatureRenderer(); featureRenderer = spy(featureRenderer); featureRenderer.scenarioRenderer = scenarioRenderer; String resultDoc = featureRenderer.renderFeatureScenarios(feature, new CukedoctorDocumentBuilderImpl().createNestedBuilder().createNestedBuilder()); assertThat(resultDoc).isEqualTo("==== Scenario: scenario 1" + newLine() + "description" + newLine() + newLine() + "==== Scenario: scenario 2" + newLine() + "description 2" + newLine() + newLine()); }
@Test public void shouldNotRenderScenarioWithSkipDocsTag() { final Feature feature = FeatureBuilder.instance().aFeatureWithOneScenarioWithOnePassingStep(); Scenario scenarioToSkip = ScenarioBuilder.instance().name("scenario to skip").tag(new Tag("@skipDocs")). type(Type.scenario).build(); ; feature.getScenarios().add(scenarioToSkip); List<Feature> features = new ArrayList<>(); features.add(feature); CukedoctorFeatureRenderer featureRenderer = new CukedoctorFeatureRenderer(); String resultDoc = featureRenderer.renderFeatureScenarios(feature, new CukedoctorDocumentBuilderImpl().createNestedBuilder().createNestedBuilder()); assertThat(resultDoc). doesNotContain("scenario to skip"). isEqualTo("==== Scenario: scenario" + newLine() + "description" + newLine() + newLine() + "==========" + newLine() + "Given::" + newLine() + "passing step icon:thumbs-up[role=\"green\",title=\"Passed\"] [small right]#(000ms)#" + newLine() + "==========" + newLine() + "" + newLine()); }
@Test public void shouldRenderFeatureScenariosWithMultipleSteps() { final Feature feature = FeatureBuilder.instance().aFeatureWithMultipleScenariosAndSteps(); List<Feature> features = new ArrayList<>(); features.add(feature); CukedoctorFeatureRenderer featureRenderer = new CukedoctorFeatureRenderer(); String resultDoc = featureRenderer.renderFeatureScenarios(feature, new CukedoctorDocumentBuilderImpl().createNestedBuilder().createNestedBuilder()); assertThat(resultDoc.replaceAll("\r", "")).isEqualTo(("==== Scenario: scenario icon:thumbs-down[role=\"red\",title=\"Failed\"]" + newLine() + "description" + newLine() + "" + newLine() + "==========" + newLine() + "Given::" + newLine() + "passing step icon:thumbs-up[role=\"green\",title=\"Passed\"] [small right]#(000ms)#" + newLine() + "When::" + newLine() + "failing step icon:thumbs-down[role=\"red\",title=\"Failed\"] [small right]#(000ms)#" + newLine() + "==========" + newLine() + "" + newLine() + "==== Scenario: scenario icon:thumbs-down[role=\"red\",title=\"Failed\"]" + newLine() + "description" + newLine() + "" + newLine() + "==========" + newLine() + "Then::" + newLine() + "skipped step icon:thumbs-down[role=\"purple\",title=\"Skipped\"] [small right]#(000ms)#" + newLine() + "==========" + newLine() + "" + newLine() + "==== Scenario: scenario icon:thumbs-down[role=\"red\",title=\"Failed\"]" + newLine() + "description" + newLine() + "" + newLine() + "==========" + newLine() + "Given::" + newLine() + "undefined step icon:thumbs-down[role=\"yellow\",title=\"Undefined\"] [small right]#(000ms)#" + newLine() + "==========" + newLine() + "" + newLine()).replaceAll("\r", "")); }