@Test public void shouldIgnoreMetaFilteringInGivenStoriesIfConfigured() throws Throwable { // Given Scenario scenario = new Scenario( "scenario", new Meta(asList("run false")), new GivenStories("/path/to/given/story"), ExamplesTable.EMPTY, asList("anotherSuccessfulStep")); Story story = new Story( "", new Description("story"), new Meta(asList("run false")), Narrative.EMPTY, new GivenStories("/path/to/given/story"), asList(scenario)); // When MetaFilter filter = new MetaFilter("+run true"); FilteredStory ignoreMeta = new FilteredStory( filter, story, new StoryControls().doIgnoreMetaFiltersIfGivenStory(true), true); // Then assertThat(ignoreMeta.allowed(), is(true)); assertThat(ignoreMeta.allowed(scenario), is(true)); // When FilteredStory doNotIgnoreMeta = new FilteredStory( filter, story, new StoryControls().doIgnoreMetaFiltersIfGivenStory(false), true); // Then assertThat(doNotIgnoreMeta.allowed(), is(false)); assertThat(doNotIgnoreMeta.allowed(scenario), is(false)); }
private void runCancellable(RunContext context, Story story, Map<String, String> storyParameters) throws Throwable { if (!context.givenStory()) { reporter.set(reporterFor(context, story)); } pendingStepStrategy.set(context.configuration().pendingStepStrategy()); failureStrategy.set(context.configuration().failureStrategy()); resetStoryFailure(context); if (context.dryRun()) { reporter.get().dryRun(); } if (context.configuration().storyControls().resetStateBeforeStory()) { context.resetState(); } // run before story steps, if any reporter.get().beforeStory(story, context.givenStory()); boolean storyAllowed = true; FilteredStory filterContext = context.filter(story); Meta storyMeta = story.getMeta(); if (!filterContext.allowed()) { reporter.get().storyNotAllowed(story, context.metaFilterAsString()); storyAllowed = false; } if (storyAllowed) { reporter.get().narrative(story.getNarrative()); runBeforeOrAfterStorySteps(context, story, Stage.BEFORE); addMetaParameters(storyParameters, storyMeta); runGivenStories(story.getGivenStories(), storyParameters, context); // determine if before and after scenario steps should be run boolean runBeforeAndAfterScenarioSteps = shouldRunBeforeOrAfterScenarioSteps(context); reporter.get().lifecyle(story.getLifecycle()); for (Scenario scenario : story.getScenarios()) { // scenario also inherits meta from story boolean scenarioAllowed = true; if (failureOccurred(context) && context.configuration().storyControls().skipScenariosAfterFailure()) { continue; } reporter.get().beforeScenario(scenario.getTitle()); reporter.get().scenarioMeta(scenario.getMeta()); if (!filterContext.allowed(scenario)) { reporter.get().scenarioNotAllowed(scenario, context.metaFilterAsString()); scenarioAllowed = false; } if (scenarioAllowed) { if (context.configuration().storyControls().resetStateBeforeScenario()) { context.resetState(); } Meta storyAndScenarioMeta = scenario.getMeta().inheritFrom(storyMeta); // run before scenario steps, if allowed if (runBeforeAndAfterScenarioSteps) { runBeforeOrAfterScenarioSteps( context, scenario, storyAndScenarioMeta, Stage.BEFORE, ScenarioType.NORMAL); } if (isParameterisedByExamples(scenario)) { // run parametrised scenarios by examples runScenariosParametrisedByExamples( context, scenario, story.getLifecycle(), storyAndScenarioMeta); } else { // run as plain old scenario runStepWithLifecycle( context, story.getLifecycle(), storyParameters, scenario, storyAndScenarioMeta); } // run after scenario steps, if allowed if (runBeforeAndAfterScenarioSteps) { runBeforeOrAfterScenarioSteps( context, scenario, storyAndScenarioMeta, Stage.AFTER, ScenarioType.NORMAL); } } reporter.get().afterScenario(); } // run after story steps, if any runBeforeOrAfterStorySteps(context, story, Stage.AFTER); } reporter.get().afterStory(context.givenStory()); // handle any failure according to strategy if (!context.givenStory()) { handleStoryFailureByStrategy(); } }