Search in sources :

Example 61 with Story

use of org.jbehave.core.model.Story in project jbehave-core by jbehave.

the class NullStoryReporterBehaviour method shouldOnlyReportOverriddenMethods.

@Test
public void shouldOnlyReportOverriddenMethods() {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    final PrintStream printStream = new PrintStream(out);
    StoryReporter reporter = new NullStoryReporter() {

        @Override
        public void beforeStory(Story story, boolean givenStory) {
            printStream.println("beforeStory");
        }

        @Override
        public void afterStory(boolean givenStory) {
            printStream.println("afterStory");
        }
    };
    StoryNarrator.narrateAnInterestingStory(reporter, false);
    assertThat(out.toString(), Matchers.equalTo("beforeStory" + NL + "afterStory" + NL));
}
Also used : PrintStream(java.io.PrintStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Story(org.jbehave.core.model.Story) Test(org.junit.Test)

Example 62 with Story

use of org.jbehave.core.model.Story in project jbehave-core by jbehave.

the class SilentSuccessFilterBehaviour method shouldNotPassSilentlyOutputNotAllowedByMetaFilter.

@Test
public void shouldNotPassSilentlyOutputNotAllowedByMetaFilter() {
    // Given
    Story story = new Story();
    Scenario scenario = new Scenario();
    String metaFilter = "";
    // When
    filter.storyNotAllowed(story, metaFilter);
    filter.scenarioNotAllowed(scenario, metaFilter);
    // Then
    InOrder inOrder = inOrder(delegate);
    inOrder.verify(delegate).storyNotAllowed(story, metaFilter);
    inOrder.verify(delegate).scenarioNotAllowed(scenario, metaFilter);
}
Also used : InOrder(org.mockito.InOrder) Story(org.jbehave.core.model.Story) Scenario(org.jbehave.core.model.Scenario) Test(org.junit.Test)

Example 63 with Story

use of org.jbehave.core.model.Story in project jbehave-core by jbehave.

the class MarkUnmatchedStepsAsPendingBehaviour method shouldInvokeBeforeOrAfterStoryWithParameter.

@Test
public void shouldInvokeBeforeOrAfterStoryWithParameter() throws Exception {
    BeforeOrAfterStoryWithParameter steps = new BeforeOrAfterStoryWithParameter();
    Story story = mock(Story.class);
    when(story.getMeta()).thenReturn(beforeAndAfterMeta());
    List<Step> beforeSteps = stepCollector.collectBeforeOrAfterStorySteps(asList((CandidateSteps) steps), story, Stage.BEFORE, false);
    beforeSteps.get(0).perform(null);
    assertThat(steps.value, equalTo("before"));
    List<Step> afterSteps = stepCollector.collectBeforeOrAfterStorySteps(asList((CandidateSteps) steps), story, Stage.AFTER, false);
    afterSteps.get(0).perform(null);
    assertThat(steps.value, equalTo("after"));
}
Also used : PendingStep(org.jbehave.core.steps.StepCreator.PendingStep) Story(org.jbehave.core.model.Story) Test(org.junit.Test)

Example 64 with Story

use of org.jbehave.core.model.Story in project jbehave-core by jbehave.

the class MarkUnmatchedStepsAsPendingBehaviour method shouldCollectBeforeAndAfterStoryAnnotatedSteps.

@Test
public void shouldCollectBeforeAndAfterStoryAnnotatedSteps() {
    // Given some candidate steps classes with before and after story
    // methods
    Story story = new Story();
    Meta storyMeta = story.getMeta();
    CandidateSteps steps1 = mock(Steps.class);
    CandidateSteps steps2 = mock(Steps.class);
    BeforeOrAfterStep bafStep11 = mock(BeforeOrAfterStep.class);
    BeforeOrAfterStep bafStep21 = mock(BeforeOrAfterStep.class);
    BeforeOrAfterStep bafStep12 = mock(BeforeOrAfterStep.class);
    BeforeOrAfterStep bafStep22 = mock(BeforeOrAfterStep.class);
    Step stepBefore1 = mock(Step.class);
    Step stepBefore2 = mock(Step.class);
    Step stepAfter1 = mock(Step.class);
    Step stepAfter2 = mock(Step.class);
    boolean givenStory = false;
    when(bafStep11.getStage()).thenReturn(Stage.BEFORE);
    when(bafStep11.createStepWith(storyMeta)).thenReturn(stepBefore1);
    when(bafStep21.getStage()).thenReturn(Stage.BEFORE);
    when(bafStep21.createStepWith(storyMeta)).thenReturn(stepBefore2);
    when(bafStep12.getStage()).thenReturn(Stage.AFTER);
    when(bafStep12.createStepWith(storyMeta)).thenReturn(stepAfter1);
    when(bafStep22.getStage()).thenReturn(Stage.AFTER);
    when(bafStep22.createStepWith(storyMeta)).thenReturn(stepAfter2);
    when(steps1.listBeforeOrAfterStory(givenStory)).thenReturn(asList(bafStep11, bafStep12));
    when(steps2.listBeforeOrAfterStory(givenStory)).thenReturn(asList(bafStep21, bafStep22));
    // When we collect the list of steps
    List<Step> beforeSteps = stepCollector.collectBeforeOrAfterStorySteps(asList(steps1, steps2), story, Stage.BEFORE, givenStory);
    List<Step> afterSteps = stepCollector.collectBeforeOrAfterStorySteps(asList(steps1, steps2), story, Stage.AFTER, givenStory);
    // Then all before and after steps should be added
    assertThat(beforeSteps, equalTo(asList(stepBefore1, stepBefore2)));
    assertThat(afterSteps, equalTo(asList(stepAfter1, stepAfter2)));
}
Also used : Meta(org.jbehave.core.model.Meta) PendingStep(org.jbehave.core.steps.StepCreator.PendingStep) Story(org.jbehave.core.model.Story) Test(org.junit.Test)

Example 65 with Story

use of org.jbehave.core.model.Story in project jbehave-core by jbehave.

the class GherkinStoryParserBehaviour method shouldParseStoryWithBackground.

@Test
public void shouldParseStoryWithBackground() throws IOException {
    String storyAsText = "Feature: Hello Car\n\n" + "Background:\n" + "Given I have a license\n\n" + "Scenario: Car can drive\n" + "Given I have a car with 4 wheels\n" + "Then I can drive it.\n";
    Story story = storyParser.parseStory(storyAsText);
    assertThat(story.getDescription().asString(), equalTo("Hello Car"));
    assertThat(story.getLifecycle().getBeforeSteps(Scope.SCENARIO), hasItem("Given I have a license"));
    assertThat(story.getScenarios().get(0).getSteps().size(), equalTo(2));
}
Also used : Story(org.jbehave.core.model.Story) Test(org.junit.Test)

Aggregations

Story (org.jbehave.core.model.Story)71 Test (org.junit.Test)58 Matchers.containsString (org.hamcrest.Matchers.containsString)41 GivenStory (org.jbehave.core.model.GivenStory)39 Scenario (org.jbehave.core.model.Scenario)29 Meta (org.jbehave.core.model.Meta)11 HashMap (java.util.HashMap)10 ByteArrayOutputStream (java.io.ByteArrayOutputStream)9 PrintStream (java.io.PrintStream)9 ArrayList (java.util.ArrayList)9 JUnitStory (org.jbehave.core.junit.JUnitStory)9 OutputStream (java.io.OutputStream)8 InjectableEmbedder (org.jbehave.core.InjectableEmbedder)8 UsingEmbedder (org.jbehave.core.annotations.UsingEmbedder)8 Configuration (org.jbehave.core.configuration.Configuration)8 MostUsefulConfiguration (org.jbehave.core.configuration.MostUsefulConfiguration)8 BatchFailures (org.jbehave.core.failures.BatchFailures)8 StoryPathResolver (org.jbehave.core.io.StoryPathResolver)8 Narrative (org.jbehave.core.model.Narrative)8 RunContext (org.jbehave.core.embedder.PerformableTree.RunContext)7