Search in sources :

Example 1 with OutcomesTable

use of org.jbehave.core.model.OutcomesTable 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 2 with OutcomesTable

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

the class PrintStreamOutputBehaviour method shouldUseCustomDateFormatInOutcomesTable.

@Test
public void shouldUseCustomDateFormatInOutcomesTable() {
    // Given
    OutputStream out = new ByteArrayOutputStream();
    StoryReporter reporter = new TxtOutput(new PrintStream(out));
    // When
    OutcomesTable outcomesTable = new OutcomesTable(new LocalizedKeywords(), "dd/MM/yyyy");
    Date actualDate = StoryNarrator.dateFor("01/01/2011");
    Date expectedDate = StoryNarrator.dateFor("02/01/2011");
    outcomesTable.addOutcome("A wrong date", actualDate, new IsDateEqual(expectedDate, outcomesTable.getDateFormat()));
    try {
        outcomesTable.verify();
    } catch (UUIDExceptionWrapper e) {
        reporter.failedOutcomes("some step", ((OutcomesFailed) e.getCause()).outcomesTable());
    }
    // Then
    String expected = "some step (FAILED)\n" + "(org.jbehave.core.model.OutcomesTable$OutcomesFailed)\n" + "|Description|Value|Matcher|Verified|\n" + "|A wrong date|01/01/2011|\"02/01/2011\"|No|\n";
    assertThat(dos2unix(out.toString()), equalTo(expected));
}
Also used : OutcomesFailed(org.jbehave.core.model.OutcomesTable.OutcomesFailed) LocalizedKeywords(org.jbehave.core.i18n.LocalizedKeywords) OutcomesTable(org.jbehave.core.model.OutcomesTable) Date(java.util.Date) IsDateEqual(org.jbehave.core.reporters.StoryNarrator.IsDateEqual) UUIDExceptionWrapper(org.jbehave.core.failures.UUIDExceptionWrapper) Test(org.junit.Test)

Example 3 with OutcomesTable

use of org.jbehave.core.model.OutcomesTable 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 4 with OutcomesTable

use of org.jbehave.core.model.OutcomesTable 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)

Example 5 with OutcomesTable

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

the class GherkinSteps method thenICanDriveThemAccordingTo.

@Then("I can drive them according to wheels: $table")
public void thenICanDriveThemAccordingTo(ExamplesTable table) {
    OutcomesTable outcomes = new OutcomesTable();
    for (Parameters row : table.getRowsAsParameters()) {
        Integer wheels = row.valueAs("wheels", Integer.class);
        Boolean canDriveWith = car.canDriveWith(wheels);
        outcomes.addOutcome("wheels " + wheels, canDriveWith, Matchers.is(row.valueAs("can_drive", Boolean.class)));
    }
    outcomes.verify();
}
Also used : Parameters(org.jbehave.core.steps.Parameters) OutcomesTable(org.jbehave.core.model.OutcomesTable) Then(org.jbehave.core.annotations.Then)

Aggregations

OutcomesTable (org.jbehave.core.model.OutcomesTable)8 UUIDExceptionWrapper (org.jbehave.core.failures.UUIDExceptionWrapper)5 Test (org.junit.Test)4 Then (org.jbehave.core.annotations.Then)3 ExamplesTable (org.jbehave.core.model.ExamplesTable)3 OutcomesFailed (org.jbehave.core.model.OutcomesTable.OutcomesFailed)3 Story (org.jbehave.core.model.Story)3 HashMap (java.util.HashMap)2 LocalizedKeywords (org.jbehave.core.i18n.LocalizedKeywords)2 GivenStories (org.jbehave.core.model.GivenStories)2 Scenario (org.jbehave.core.model.Scenario)2 Parameters (org.jbehave.core.steps.Parameters)2 InOrder (org.mockito.InOrder)2 Date (java.util.Date)1 Locale (java.util.Locale)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1 PendingStepFound (org.jbehave.core.failures.PendingStepFound)1 Description (org.jbehave.core.model.Description)1 Narrative (org.jbehave.core.model.Narrative)1 IsDateEqual (org.jbehave.core.reporters.StoryNarrator.IsDateEqual)1