private void removeFeatureIfNoScenariosMatchTags(String filterExpression, Iterator<FeatureToken> fi) { //remove all filtered scenarios from this feature FeatureToken feature = fi.next(); int startOrEndCount = 0; for (Iterator<ScenarioToken> si = feature.getScenarios().iterator(); si.hasNext(); ) { ScenarioToken scenario = si.next(); if ( scenario.isFeatureStartScenario() || scenario.isFeatureEndScenario() ) { log.trace("Not removing since this is a start or end feature scenario"); startOrEndCount ++; } else if (! tagExpressionEvaluator.shouldRunScenarioWithTags(filterExpression, scenario.getTags())) { log.debug("Removing scenario " + scenario + " which does not match tag " + filterExpression); si.remove(); } } //if there are no scenarios left (apart from special start or end feature scenarios which are never tagged), //then remove this feature from the list to run if (feature.getScenarios().size() == startOrEndCount) { log.debug("Will not run feature " + fi + " which does not have any scenarios which " + "passed the tag filter " + filterExpression); fi.remove(); } }
@Override public ScenarioTokenBean marshal(ScenarioToken s) throws Exception { ScenarioTokenBean result = new ScenarioTokenBean(); result.setTokenId(s.getTokenId()); result.setName(s.getName()); result.setSteps(s.getSteps()); List<String> tags = s.getTags(); result.setTags(tags.size() == 0 ? null : FormattingUtils.getAsCsv(s.getTags())); result.setEndState(s.getEndState()); return result; }
@Test public void scenarioInheritsTagsFromFeature() throws Exception { File f = getFileResourceWithName(TEST_FEATURE_FILE); FeatureFileParser p = new FeatureFileParser(); List<FeatureToken> features = p.parse(new FileReaderSupplier(f)); assertEquals("Wrong number of features loaded", 1, features.size()); FeatureToken feature = features.get(0); // the first scenario should inherit the two tags from the parent feature only ScenarioToken scenario = feature.getScenarios().get(0); List<String> scenarioTags = scenario.getTags(); assertEquals("Wrong number of tags found on scenario 1", 2, scenarioTags.size()); // check the two tag values assertTrue(scenarioTags.contains("@tagA")); assertTrue(scenarioTags.contains("@tagB")); }
@Test public void outlineScenarioInheritsTagsFromFeatureAndAddsOwn() throws Exception { File f = getFileResourceWithName(TEST_FEATURE_FILE); FeatureFileParser p = new FeatureFileParser(); List<FeatureToken> features = p.parse(new FileReaderSupplier(f)); FeatureToken feature = features.get(0); // remaining scenarios (created from an outline) should have 2 inherited tags from the parent feature and one of their own for (int i = 2; i < feature.getScenarios().size(); i++) { ScenarioToken scenario3 = feature.getScenarios().get(2); List<String> scenario3tags = scenario3.getTags(); assertEquals("Wrong number of tags found on scenario " + (i + 1), 3, scenario3tags.size()); assertTrue(scenario3tags.contains("@tagA")); assertTrue(scenario3tags.contains("@tagB")); assertTrue(scenario3tags.contains("@tagF")); } }
@Test public void scenarioInheritsTagsFromFeatureAndAddsOwn() throws Exception { File f = getFileResourceWithName(TEST_FEATURE_FILE); FeatureFileParser p = new FeatureFileParser(); List<FeatureToken> features = p.parse(new FileReaderSupplier(f)); FeatureToken feature = features.get(0); // the second scenario should inherit the two tags from the parent feature and declare three of its own too ScenarioToken scenario = feature.getScenarios().get(1); List<String> scenarioTags = scenario.getTags(); assertEquals("Wrong number of tags found on scenario 2", 5, scenarioTags.size()); // check the tag values assertTrue(scenarioTags.contains("@tagA")); assertTrue(scenarioTags.contains("@tagB")); assertTrue(scenarioTags.contains("@tagC")); assertTrue(scenarioTags.contains("@tagD")); assertTrue(scenarioTags.contains("@tagE")); }