Search in sources :

Example 21 with Story

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

the class RegexStoryParserBehaviour method shouldParseStoryWithStepsContainingKeywordsAtStartOfOtherWords.

@Test
public void shouldParseStoryWithStepsContainingKeywordsAtStartOfOtherWords() {
    String wholeStory = "Meta: @some" + NL + "Given a scenario Givenly" + NL + "When I parse it to Whenever" + NL + "And I parse it to Anderson" + NL + "!-- ignore me too" + NL + "Then I should get steps Thenact";
    Story story = parser.parseStory(wholeStory, storyPath);
    List<String> steps = story.getScenarios().get(0).getSteps();
    assertThat(steps.get(0), equalTo("Given a scenario Givenly"));
    assertThat(steps.get(1), equalTo("When I parse it to Whenever"));
    assertThat(steps.get(2), equalTo("And I parse it to Anderson"));
    assertThat(steps.get(3), equalTo("!-- ignore me too"));
    assertThat(steps.get(4), equalTo("Then I should get steps Thenact"));
}
Also used : Matchers.containsString(org.hamcrest.Matchers.containsString) GivenStory(org.jbehave.core.model.GivenStory) Story(org.jbehave.core.model.Story) Test(org.junit.Test)

Example 22 with Story

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

the class RegexStoryParserBehaviour method shouldParseStoryWithLifecycle.

@Test
public void shouldParseStoryWithLifecycle() {
    String wholeStory = "Lifecycle: " + NL + "Before:" + NL + NL + "Given a step before each scenario" + NL + "And another before step" + NL + "After:" + NL + NL + "Given a step after each scenario" + NL + "And another after step" + NL + "Scenario:" + NL + "Given a scenario";
    Story story = parser.parseStory(wholeStory, storyPath);
    List<String> beforeSteps = story.getLifecycle().getBeforeSteps();
    assertThat(beforeSteps.get(0), equalTo("Given a step before each scenario"));
    assertThat(beforeSteps.get(1), equalTo("And another before step"));
    List<String> afterSteps = story.getLifecycle().getAfterSteps();
    assertThat(afterSteps.get(0), equalTo("Given a step after each scenario"));
    assertThat(afterSteps.get(1), equalTo("And another after step"));
    Scenario scenario = story.getScenarios().get(0);
    List<String> steps = scenario.getSteps();
    assertThat(steps.get(0), equalTo("Given a scenario"));
}
Also used : Matchers.containsString(org.hamcrest.Matchers.containsString) GivenStory(org.jbehave.core.model.GivenStory) Story(org.jbehave.core.model.Story) Scenario(org.jbehave.core.model.Scenario) Test(org.junit.Test)

Example 23 with Story

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

the class PostStoryStatisticsCollectorBehaviour method narrateAnInterestingStory.

private void narrateAnInterestingStory() {
    Story story = new Story("/path/to/story", new Description("An interesting story"), new Narrative("renovate my house", "customer", "get a loan"), new ArrayList<Scenario>());
    reporter.dryRun();
    // begin story
    reporter.beforeStory(story, false);
    // 1st scenario
    reporter.beforeScenario(new Scenario("I ask for a loan", Meta.EMPTY));
    reporter.givenStories(asList("path/to/story1", "path/to/story2"));
    // 1st given story
    reporter.beforeStory(story, true);
    reporter.beforeScenario(new Scenario("a scenario without steps", Meta.EMPTY));
    reporter.afterScenario();
    reporter.afterStory(true);
    // 2nd given story
    reporter.beforeStory(story, true);
    reporter.beforeScenario(new Scenario("the bank has $300 to loan", Meta.EMPTY));
    reporter.givenStories(asList("path/to/nested/story1"));
    reporter.beforeStory(story, true);
    reporter.beforeScenario(new Scenario("initialise static", Meta.EMPTY));
    reporter.successful("the bank has customers");
    reporter.afterScenario();
    reporter.afterStory(true);
    reporter.afterScenario();
    reporter.afterStory(true);
    reporter.successful("Given I have a balance of $50");
    reporter.ignorable("!-- Then ignore me");
    reporter.comment("!-- A comment");
    reporter.successful("When I request $20");
    reporter.successful("When I ask Liz for a loan of $100");
    reporter.afterScenario();
    // 2nd scenario
    reporter.beforeScenario(new Scenario("A failing scenario", Meta.EMPTY));
    OutcomesTable outcomesTable = new OutcomesTable();
    outcomesTable.addOutcome("I don't return all", 100.0, equalTo(50.));
    try {
        outcomesTable.verify();
    } catch (UUIDExceptionWrapper e) {
        reporter.failedOutcomes("Then I don't return loan", ((OutcomesFailed) e.getCause()).outcomesTable());
    }
    reporter.notPerformed("Then I should have $20");
    ExamplesTable table = new ExamplesTable("|money|to|\n|$30|Mauro|\n|$50|Paul|\n");
    reporter.beforeExamples(asList("Given money <money>", "Then I give it to <to>"), table);
    reporter.example(table.getRow(0));
    reporter.example(table.getRow(1));
    reporter.afterExamples();
    reporter.afterScenario();
    // 3rd scenario
    reporter.beforeScenario(new Scenario("A pending scenario", Meta.EMPTY));
    reporter.pending("When I have some money");
    reporter.notPerformed("Then I should have $20");
    reporter.afterScenario();
    // end story
    reporter.afterStory(false);
}
Also used : Description(org.jbehave.core.model.Description) OutcomesFailed(org.jbehave.core.model.OutcomesTable.OutcomesFailed) Narrative(org.jbehave.core.model.Narrative) ExamplesTable(org.jbehave.core.model.ExamplesTable) Story(org.jbehave.core.model.Story) OutcomesTable(org.jbehave.core.model.OutcomesTable) Scenario(org.jbehave.core.model.Scenario) UUIDExceptionWrapper(org.jbehave.core.failures.UUIDExceptionWrapper)

Example 24 with Story

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

the class SilentSuccessFilterBehaviour method shouldPassSilentlyOutputFromSuccessfulScenarios.

@Test
public void shouldPassSilentlyOutputFromSuccessfulScenarios() {
    // Given
    ExamplesTable examplesTable = new ExamplesTable("|one|two|\n|1|2|\n");
    UUIDExceptionWrapper anException = new UUIDExceptionWrapper(new IllegalArgumentException());
    Story story = new Story();
    GivenStories givenStories = new GivenStories("path/to/story1,path/to/story2");
    List<String> givenStoryPaths = asList("path/to/story1", "path/to/story2");
    // When
    Scenario scenario1 = new Scenario("My scenario 1", Meta.EMPTY);
    filter.dryRun();
    filter.beforeStory(story, false);
    filter.beforeScenario(scenario1);
    filter.scenarioMeta(Meta.EMPTY);
    filter.successful("Given step 1.1");
    filter.ignorable("!-- Then ignore me");
    filter.comment("!-- A comment");
    filter.successful("When step 1.2");
    filter.successful("Then step 1.3");
    filter.afterScenario();
    Scenario scenario2 = new Scenario("My scenario 2", Meta.EMPTY);
    filter.beforeScenario(scenario2);
    filter.givenStories(givenStories);
    filter.givenStories(givenStoryPaths);
    filter.successful("Given step 2.1");
    filter.pending("When step 2.2");
    filter.notPerformed("Then step 2.3");
    filter.afterScenario();
    Scenario scenario3 = new Scenario("My scenario 3", Meta.EMPTY);
    filter.beforeScenario(scenario3);
    filter.beforeExamples(asList("Given step <one>", "Then step <two>"), examplesTable);
    Map<String, String> tableRow = new HashMap<>();
    filter.example(tableRow);
    filter.successful("Given step 3.1");
    filter.successful("When step 3.2");
    filter.ignorable("!-- Then ignore me too");
    filter.comment("!-- One more comment");
    filter.failed("Then step 3.3", anException);
    OutcomesTable outcomesTable = new OutcomesTable();
    filter.failedOutcomes("When failed outcomes", outcomesTable);
    filter.afterExamples();
    filter.afterScenario();
    Scenario scenario4 = new Scenario("My scenario 4", Meta.EMPTY);
    filter.beforeScenario(scenario4);
    filter.successful("Given step 4.1");
    filter.successful("When step 4.2");
    filter.successful("Then step 4.3");
    filter.afterScenario();
    filter.afterStory(false);
    // Then
    InOrder inOrder = inOrder(delegate);
    // Scenarios 1 and 4 are successful
    verify(delegate, never()).beforeScenario(scenario1);
    verify(delegate, never()).successful("Given step 1.1");
    verify(delegate, never()).ignorable("!-- Then ignore me");
    verify(delegate, never()).comment("!-- A comment");
    verify(delegate, never()).successful("When step 1.2");
    verify(delegate, never()).successful("Then step 1.3");
    verify(delegate, never()).beforeScenario(scenario4);
    verify(delegate, never()).successful("Given step 4.1");
    verify(delegate, never()).successful("When step 4.2");
    verify(delegate, never()).successful("Then step 4.3");
    // Scenarios 2 and 3 have pending or failed steps
    inOrder.verify(delegate).dryRun();
    inOrder.verify(delegate).beforeStory(story, false);
    inOrder.verify(delegate).beforeScenario(scenario2);
    inOrder.verify(delegate).givenStories(givenStories);
    inOrder.verify(delegate).givenStories(givenStoryPaths);
    inOrder.verify(delegate).successful("Given step 2.1");
    inOrder.verify(delegate).pending("When step 2.2");
    inOrder.verify(delegate).notPerformed("Then step 2.3");
    inOrder.verify(delegate).afterScenario();
    inOrder.verify(delegate).beforeScenario(scenario3);
    inOrder.verify(delegate).beforeExamples(asList("Given step <one>", "Then step <two>"), examplesTable);
    inOrder.verify(delegate).example(tableRow);
    inOrder.verify(delegate).successful("Given step 3.1");
    inOrder.verify(delegate).successful("When step 3.2");
    inOrder.verify(delegate).ignorable("!-- Then ignore me too");
    inOrder.verify(delegate).comment("!-- One more comment");
    inOrder.verify(delegate).failed("Then step 3.3", anException);
    inOrder.verify(delegate).failedOutcomes("When failed outcomes", outcomesTable);
    inOrder.verify(delegate).afterExamples();
    inOrder.verify(delegate).afterScenario();
    inOrder.verify(delegate).afterStory(false);
}
Also used : GivenStories(org.jbehave.core.model.GivenStories) InOrder(org.mockito.InOrder) HashMap(java.util.HashMap) ExamplesTable(org.jbehave.core.model.ExamplesTable) Story(org.jbehave.core.model.Story) OutcomesTable(org.jbehave.core.model.OutcomesTable) UUIDExceptionWrapper(org.jbehave.core.failures.UUIDExceptionWrapper) Scenario(org.jbehave.core.model.Scenario) Test(org.junit.Test)

Example 25 with Story

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

the class SilentSuccessFilterBehaviour method shouldPassSilentlyOutputFromSuccessfulScenariosWithDeprecatedBeforeScenario.

@Test
public void shouldPassSilentlyOutputFromSuccessfulScenariosWithDeprecatedBeforeScenario() {
    // Given
    ExamplesTable examplesTable = new ExamplesTable("|one|two|\n|1|2|\n");
    UUIDExceptionWrapper anException = new UUIDExceptionWrapper(new IllegalArgumentException());
    Story story = new Story();
    GivenStories givenStories = new GivenStories("path/to/story1,path/to/story2");
    List<String> givenStoryPaths = asList("path/to/story1", "path/to/story2");
    // When
    filter.dryRun();
    filter.beforeStory(story, false);
    filter.beforeScenario("My scenario 1");
    filter.scenarioMeta(Meta.EMPTY);
    filter.successful("Given step 1.1");
    filter.ignorable("!-- Then ignore me");
    filter.comment("!-- A comment");
    filter.successful("When step 1.2");
    filter.successful("Then step 1.3");
    filter.afterScenario();
    filter.beforeScenario("My scenario 2");
    filter.givenStories(givenStories);
    filter.givenStories(givenStoryPaths);
    filter.successful("Given step 2.1");
    filter.pending("When step 2.2");
    filter.notPerformed("Then step 2.3");
    filter.afterScenario();
    filter.beforeScenario("My scenario 3");
    filter.beforeExamples(asList("Given step <one>", "Then step <two>"), examplesTable);
    Map<String, String> tableRow = new HashMap<>();
    filter.example(tableRow);
    filter.successful("Given step 3.1");
    filter.successful("When step 3.2");
    filter.ignorable("!-- Then ignore me too");
    filter.comment("!-- One more comment");
    filter.failed("Then step 3.3", anException);
    OutcomesTable outcomesTable = new OutcomesTable();
    filter.failedOutcomes("When failed outcomes", outcomesTable);
    filter.afterExamples();
    filter.afterScenario();
    filter.beforeScenario("My scenario 4");
    filter.successful("Given step 4.1");
    filter.successful("When step 4.2");
    filter.successful("Then step 4.3");
    filter.afterScenario();
    filter.afterStory(false);
    // Then
    InOrder inOrder = inOrder(delegate);
    // Scenarios 1 and 4 are successful
    verify(delegate, never()).beforeScenario("My scenario 1");
    verify(delegate, never()).successful("Given step 1.1");
    verify(delegate, never()).ignorable("!-- Then ignore me");
    verify(delegate, never()).comment("!-- A comment");
    verify(delegate, never()).successful("When step 1.2");
    verify(delegate, never()).successful("Then step 1.3");
    verify(delegate, never()).beforeScenario("My scenario 4");
    verify(delegate, never()).successful("Given step 4.1");
    verify(delegate, never()).successful("When step 4.2");
    verify(delegate, never()).successful("Then step 4.3");
    // Scenarios 2 and 3 have pending or failed steps
    inOrder.verify(delegate).dryRun();
    inOrder.verify(delegate).beforeStory(story, false);
    inOrder.verify(delegate).beforeScenario("My scenario 2");
    inOrder.verify(delegate).givenStories(givenStories);
    inOrder.verify(delegate).givenStories(givenStoryPaths);
    inOrder.verify(delegate).successful("Given step 2.1");
    inOrder.verify(delegate).pending("When step 2.2");
    inOrder.verify(delegate).notPerformed("Then step 2.3");
    inOrder.verify(delegate).afterScenario();
    inOrder.verify(delegate).beforeScenario("My scenario 3");
    inOrder.verify(delegate).beforeExamples(asList("Given step <one>", "Then step <two>"), examplesTable);
    inOrder.verify(delegate).example(tableRow);
    inOrder.verify(delegate).successful("Given step 3.1");
    inOrder.verify(delegate).successful("When step 3.2");
    inOrder.verify(delegate).ignorable("!-- Then ignore me too");
    inOrder.verify(delegate).comment("!-- One more comment");
    inOrder.verify(delegate).failed("Then step 3.3", anException);
    inOrder.verify(delegate).failedOutcomes("When failed outcomes", outcomesTable);
    inOrder.verify(delegate).afterExamples();
    inOrder.verify(delegate).afterScenario();
    inOrder.verify(delegate).afterStory(false);
}
Also used : GivenStories(org.jbehave.core.model.GivenStories) InOrder(org.mockito.InOrder) HashMap(java.util.HashMap) ExamplesTable(org.jbehave.core.model.ExamplesTable) Story(org.jbehave.core.model.Story) OutcomesTable(org.jbehave.core.model.OutcomesTable) UUIDExceptionWrapper(org.jbehave.core.failures.UUIDExceptionWrapper) 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