Search in sources :

Example 1 with StoryParser

use of org.jbehave.core.parsers.StoryParser in project jbehave-core by jbehave.

the class StoryRunnerBehaviour method shouldAllowToSkipBeforeAndAfterScenarioStepsIfGivenStory.

@Test
public void shouldAllowToSkipBeforeAndAfterScenarioStepsIfGivenStory() throws Throwable {
    // Given
    Scenario scenario1 = new Scenario("scenario 1", asList("successfulStep"));
    GivenStories givenStories = new GivenStories("/path/to/given/story1");
    Scenario scenario2 = new Scenario("scenario 2", Meta.EMPTY, givenStories, ExamplesTable.EMPTY, asList("anotherSuccessfulStep"));
    Story story1 = new Story(new Description("story 1"), Narrative.EMPTY, asList(scenario1));
    Story story2 = new Story(new Description("story 2"), Narrative.EMPTY, asList(scenario2));
    Step step = mock(Step.class);
    StepResult result = mock(StepResult.class);
    when(step.perform(null)).thenReturn(result);
    StoryParser storyParser = mock(StoryParser.class);
    StoryLoader storyLoader = mock(StoryLoader.class);
    StoryReporter reporter = mock(ConcurrentStoryReporter.class);
    StepCollector collector = mock(StepCollector.class);
    CandidateSteps mySteps = new Steps();
    Step successfulStep = mockSuccessfulStep("successfulStep");
    Step anotherSuccessfulStep = mockSuccessfulStep("anotherSuccessfulStep");
    givenStoryWithNoBeforeOrAfterSteps(story1, false, collector, mySteps);
    when(collector.collectScenarioSteps(asList(mySteps), scenario1, parameters)).thenReturn(asList(successfulStep));
    givenStoryWithNoBeforeOrAfterSteps(story2, true, collector, mySteps);
    when(collector.collectScenarioSteps(asList(mySteps), scenario2, parameters)).thenReturn(asList(anotherSuccessfulStep));
    when(storyLoader.loadStoryAsText("/path/to/given/story1")).thenReturn("storyContent");
    when(storyParser.parseStory("storyContent", "/path/to/given/story1")).thenReturn(story1);
    FailureStrategy failureStrategy = mock(FailureStrategy.class);
    Step beforeStep = mockSuccessfulStep("SuccessfulBeforeScenarioStep");
    Step afterStep = mockSuccessfulStep("SuccessfulAfterScenarioStep");
    when(collector.collectBeforeOrAfterScenarioSteps(eq(asList(mySteps)), Matchers.<Meta>any(), eq(Stage.BEFORE), eq(ScenarioType.NORMAL))).thenReturn(asList(beforeStep));
    when(collector.collectBeforeOrAfterScenarioSteps(eq(asList(mySteps)), Matchers.<Meta>any(), eq(Stage.AFTER), eq(ScenarioType.NORMAL))).thenReturn(asList(afterStep));
    // When
    StoryRunner runner = new StoryRunner();
    Configuration configuration = configurationWith(storyParser, storyLoader, reporter, collector, failureStrategy);
    configuration.storyControls().doSkipBeforeAndAfterScenarioStepsIfGivenStory(true);
    runner.run(configuration, asList(mySteps), story2);
    // Then
    verify(collector).collectScenarioSteps(asList(mySteps), scenario1, parameters);
    verify(collector).collectScenarioSteps(asList(mySteps), scenario2, parameters);
    InOrder inOrder = inOrder(beforeStep, successfulStep, anotherSuccessfulStep, afterStep);
    inOrder.verify(beforeStep).perform(null);
    inOrder.verify(successfulStep).perform(null);
    inOrder.verify(anotherSuccessfulStep).perform(null);
    inOrder.verify(afterStep).perform(null);
}
Also used : StoryReporter(org.jbehave.core.reporters.StoryReporter) ConcurrentStoryReporter(org.jbehave.core.reporters.ConcurrentStoryReporter) StoryLoader(org.jbehave.core.io.StoryLoader) InOrder(org.mockito.InOrder) Configuration(org.jbehave.core.configuration.Configuration) MostUsefulConfiguration(org.jbehave.core.configuration.MostUsefulConfiguration) AbstractStep(org.jbehave.core.steps.StepCreator.AbstractStep) RegexStoryParser(org.jbehave.core.parsers.RegexStoryParser) StoryParser(org.jbehave.core.parsers.StoryParser) AbstractStepResult(org.jbehave.core.steps.AbstractStepResult) Test(org.junit.Test)

Example 2 with StoryParser

use of org.jbehave.core.parsers.StoryParser in project jbehave-core by jbehave.

the class StoryRunnerBehaviour method shouldRunGivenStoriesAtStoryAndScenarioLevel.

@Test
public void shouldRunGivenStoriesAtStoryAndScenarioLevel() throws Throwable {
    // Given
    GivenStories storyGivenStories = new GivenStories("/path/to/given/story1");
    GivenStories scenarioGivenStories = new GivenStories("/path/to/given/story1");
    Scenario scenario1 = new Scenario("scenario 1", asList("successfulStep"));
    Scenario scenario2 = new Scenario("scenario 2", Meta.EMPTY, scenarioGivenStories, ExamplesTable.EMPTY, asList("anotherSuccessfulStep"));
    Story story1 = new Story(new Description("story 1"), Narrative.EMPTY, asList(scenario1));
    Story story2 = new Story("", new Description("story 2"), Meta.EMPTY, Narrative.EMPTY, storyGivenStories, asList(scenario2));
    Step step = mock(Step.class);
    StepResult result = mock(StepResult.class);
    when(step.perform(null)).thenReturn(result);
    StoryParser storyParser = mock(StoryParser.class);
    StoryLoader storyLoader = mock(StoryLoader.class);
    StoryReporter reporter = mock(ConcurrentStoryReporter.class);
    StepCollector collector = mock(StepCollector.class);
    CandidateSteps mySteps = new Steps();
    Step successfulStep = mockSuccessfulStep("successfulStep");
    Step anotherSuccessfulStep = mockSuccessfulStep("anotherSuccessfulStep");
    boolean givenStory = false;
    givenStoryWithNoBeforeOrAfterSteps(story1, givenStory, collector, mySteps);
    when(collector.collectScenarioSteps(asList(mySteps), scenario1, parameters)).thenReturn(asList(successfulStep));
    givenStoryWithNoBeforeOrAfterSteps(story2, givenStory, collector, mySteps);
    when(collector.collectScenarioSteps(asList(mySteps), scenario2, parameters)).thenReturn(asList(anotherSuccessfulStep));
    when(storyLoader.loadStoryAsText("/path/to/given/story1")).thenReturn("storyContent");
    when(storyParser.parseStory("storyContent", "/path/to/given/story1")).thenReturn(story1);
    givenStoryWithNoBeforeOrAfterSteps(story1, givenStory, collector, mySteps);
    givenStoryWithNoBeforeOrAfterSteps(story2, givenStory, collector, mySteps);
    FailureStrategy failureStrategy = mock(FailureStrategy.class);
    // When
    StoryRunner runner = new StoryRunner();
    Configuration configuration = configurationWith(storyParser, storyLoader, reporter, collector, failureStrategy);
    runner.run(configuration, asList(mySteps), story2);
    // Then
    InOrder inOrder = inOrder(reporter);
    inOrder.verify(reporter).beforeStory(story2, givenStory);
    inOrder.verify(reporter).givenStories(storyGivenStories);
    inOrder.verify(reporter).givenStories(scenarioGivenStories);
    inOrder.verify(reporter).successful("successfulStep");
    inOrder.verify(reporter).successful("anotherSuccessfulStep");
    inOrder.verify(reporter).afterStory(givenStory);
    verify(reporter, never()).beforeStory(story1, givenStory);
}
Also used : StoryReporter(org.jbehave.core.reporters.StoryReporter) ConcurrentStoryReporter(org.jbehave.core.reporters.ConcurrentStoryReporter) StoryLoader(org.jbehave.core.io.StoryLoader) InOrder(org.mockito.InOrder) Configuration(org.jbehave.core.configuration.Configuration) MostUsefulConfiguration(org.jbehave.core.configuration.MostUsefulConfiguration) AbstractStep(org.jbehave.core.steps.StepCreator.AbstractStep) RegexStoryParser(org.jbehave.core.parsers.RegexStoryParser) StoryParser(org.jbehave.core.parsers.StoryParser) AbstractStepResult(org.jbehave.core.steps.AbstractStepResult) Test(org.junit.Test)

Aggregations

Configuration (org.jbehave.core.configuration.Configuration)2 MostUsefulConfiguration (org.jbehave.core.configuration.MostUsefulConfiguration)2 StoryLoader (org.jbehave.core.io.StoryLoader)2 RegexStoryParser (org.jbehave.core.parsers.RegexStoryParser)2 StoryParser (org.jbehave.core.parsers.StoryParser)2 ConcurrentStoryReporter (org.jbehave.core.reporters.ConcurrentStoryReporter)2 StoryReporter (org.jbehave.core.reporters.StoryReporter)2 AbstractStepResult (org.jbehave.core.steps.AbstractStepResult)2 AbstractStep (org.jbehave.core.steps.StepCreator.AbstractStep)2 Test (org.junit.Test)2 InOrder (org.mockito.InOrder)2