Search in sources :

Example 1 with OutcomesFailed

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

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

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

the class StepResultBehaviour method shouldDescribeResultToReporter.

@Test
public void shouldDescribeResultToReporter() {
    // Given
    StoryReporter reporter = mock(StoryReporter.class);
    // When
    String successful = "Given that a step is pending or failing";
    successful(successful).describeTo(reporter);
    String pending = "When a step is performed";
    pending(pending).describeTo(reporter);
    PendingStepFound pendingStepFound = new PendingStepFound(pending);
    pending(pending, pendingStepFound).describeTo(reporter);
    String notPerformed = "Then the step should describe itself properly to reporters";
    notPerformed(notPerformed).describeTo(reporter);
    String ignorable = "!-- Then ignore me";
    ignorable(ignorable).describeTo(reporter);
    String comment = "!-- this is a comment";
    comment(comment).describeTo(reporter);
    String failed = "And any errors should appear at the end of the story";
    UUIDExceptionWrapper cause = new UUIDExceptionWrapper(new IllegalStateException());
    failed(failed, cause).describeTo(reporter);
    String failedOutcomes = "And outcomes failed";
    OutcomesTable outcomesTable = new OutcomesTable();
    failed(failedOutcomes, new UUIDExceptionWrapper(new OutcomesFailed(outcomesTable))).describeTo(reporter);
    skipped().describeTo(reporter);
    // Then
    verify(reporter).successful(successful);
    verify(reporter, times(2)).pending(pending);
    verify(reporter).notPerformed(notPerformed);
    verify(reporter).ignorable(ignorable);
    verify(reporter).comment(comment);
    verify(reporter).failed(failed, cause);
    verify(reporter).failedOutcomes(failedOutcomes, outcomesTable);
}
Also used : StoryReporter(org.jbehave.core.reporters.StoryReporter) OutcomesFailed(org.jbehave.core.model.OutcomesTable.OutcomesFailed) PendingStepFound(org.jbehave.core.failures.PendingStepFound) Matchers.containsString(org.hamcrest.Matchers.containsString) OutcomesTable(org.jbehave.core.model.OutcomesTable) UUIDExceptionWrapper(org.jbehave.core.failures.UUIDExceptionWrapper) Test(org.junit.Test)

Example 4 with OutcomesFailed

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

the class StoryNarrator method narrateAnInterestingStory.

static void narrateAnInterestingStory(StoryReporter reporter, boolean withFailure) {
    Properties meta = new Properties();
    meta.setProperty("theme", "testing");
    meta.setProperty("author", "Mauro");
    Lifecycle.Steps beforeScenarioSteps = new Lifecycle.Steps(Scope.SCENARIO, asList("Given a scenario step"));
    Lifecycle.Steps beforeStorySteps = new Lifecycle.Steps(Scope.STORY, asList("Given a story step"));
    Lifecycle.Steps afterScenarioSteps = new Lifecycle.Steps(Scope.SCENARIO, asList("Given a scenario step"));
    Lifecycle.Steps afterStorySteps = new Lifecycle.Steps(Scope.STORY, asList("Given a story step"));
    Lifecycle lifecycle = new Lifecycle(asList(beforeScenarioSteps, beforeStorySteps), asList(afterScenarioSteps, afterStorySteps));
    Story story = new Story("/path/to/story", new Description("An interesting story & special chars"), new Meta(meta), new Narrative("renovate my house", "customer", "get a loan"), GivenStories.EMPTY, lifecycle, new ArrayList<Scenario>());
    boolean givenStory = false;
    reporter.beforeStory(story, givenStory);
    reporter.dryRun();
    reporter.narrative(story.getNarrative());
    reporter.lifecyle(lifecycle);
    reporter.beforeScenario(new Scenario("I ask for a loan", Meta.EMPTY));
    reporter.beforeGivenStories();
    reporter.givenStories(asList("/given/story1", "/given/story2"));
    reporter.afterGivenStories();
    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.successful("When I ask Liz for a loan of $" + StepCreator.PARAMETER_VALUE_START + "99" + StepCreator.PARAMETER_VALUE_END);
    reporter.successful("When I write special chars <>&\"");
    reporter.successful("When I write special chars in parameter " + StepCreator.PARAMETER_VALUE_START + "<>&\"" + StepCreator.PARAMETER_VALUE_END);
    reporter.successful("When I write two parameters " + StepCreator.PARAMETER_VALUE_START + ",,," + StepCreator.PARAMETER_VALUE_END + " and " + StepCreator.PARAMETER_VALUE_START + "&&&" + StepCreator.PARAMETER_VALUE_END);
    reporter.restarted("Then I should... - try again", new RestartingScenarioFailure("hi"));
    reporter.restartedStory(story, new RestartingStoryFailure("Restarted Story"));
    reporter.storyCancelled(story, new StoryDuration(1).setDurationInSecs(2));
    if (withFailure) {
        reporter.failed("Then I should have a balance of $30", new UUIDExceptionWrapper(new Exception("Expected <30> got <25>")));
    } else {
        reporter.pending("Then I should have a balance of $30");
    }
    reporter.notPerformed("Then I should have $20");
    OutcomesTable outcomesTable = new OutcomesTable(new LocalizedKeywords(), "dd/MM/yyyy");
    outcomesTable.addOutcome("I don't return all", 100.0, equalTo(50.));
    Date actualDate = dateFor("01/01/2011");
    Date expectedDate = dateFor("02/01/2011");
    outcomesTable.addOutcome("A wrong date", actualDate, new IsDateEqual(expectedDate, outcomesTable.getDateFormat()));
    try {
        outcomesTable.verify();
    } catch (UUIDExceptionWrapper e) {
        reporter.failedOutcomes("Then I don't return loan", ((OutcomesFailed) e.getCause()).outcomesTable());
    }
    reporter.afterScenario();
    reporter.beforeScenario(new Scenario("Parametrised Scenario", Meta.EMPTY));
    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.successful("Given money $30");
    reporter.successful("Then I give it to Mauro");
    reporter.example(table.getRow(1));
    reporter.successful("Given money $50");
    reporter.successful("Then I give it to Paul");
    if (withFailure) {
        reporter.failed("Then I should have a balance of $30", new UUIDExceptionWrapper(new Exception("Expected <30> got <25>")));
    } else {
        reporter.pending("Then I should have a balance of $30");
    }
    reporter.afterExamples();
    reporter.afterScenario();
    String method1 = "@When(\"something \\\"$param\\\"\")\n" + "@Pending\n" + "public void whenSomething() {\n" + "  // PENDING\n" + "}\n";
    String method2 = "@Then(\"something is <param1>\")\n" + "@Pending\n" + "public void thenSomethingIsParam1() {\n" + "  // PENDING\n" + "}\n";
    reporter.pendingMethods(asList(method1, method2));
    reporter.afterStory(givenStory);
}
Also used : RestartingStoryFailure(org.jbehave.core.failures.RestartingStoryFailure) OutcomesFailed(org.jbehave.core.model.OutcomesTable.OutcomesFailed) LocalizedKeywords(org.jbehave.core.i18n.LocalizedKeywords) Properties(java.util.Properties) ParseException(java.text.ParseException) Date(java.util.Date) RestartingScenarioFailure(org.jbehave.core.failures.RestartingScenarioFailure) UUIDExceptionWrapper(org.jbehave.core.failures.UUIDExceptionWrapper)

Aggregations

UUIDExceptionWrapper (org.jbehave.core.failures.UUIDExceptionWrapper)4 OutcomesFailed (org.jbehave.core.model.OutcomesTable.OutcomesFailed)4 OutcomesTable (org.jbehave.core.model.OutcomesTable)3 Date (java.util.Date)2 LocalizedKeywords (org.jbehave.core.i18n.LocalizedKeywords)2 Test (org.junit.Test)2 ParseException (java.text.ParseException)1 Properties (java.util.Properties)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1 PendingStepFound (org.jbehave.core.failures.PendingStepFound)1 RestartingScenarioFailure (org.jbehave.core.failures.RestartingScenarioFailure)1 RestartingStoryFailure (org.jbehave.core.failures.RestartingStoryFailure)1 Description (org.jbehave.core.model.Description)1 ExamplesTable (org.jbehave.core.model.ExamplesTable)1 Narrative (org.jbehave.core.model.Narrative)1 Scenario (org.jbehave.core.model.Scenario)1 Story (org.jbehave.core.model.Story)1 IsDateEqual (org.jbehave.core.reporters.StoryNarrator.IsDateEqual)1 StoryReporter (org.jbehave.core.reporters.StoryReporter)1