Search in sources :

Example 1 with UUIDExceptionWrapper

use of org.jbehave.core.failures.UUIDExceptionWrapper 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 UUIDExceptionWrapper

use of org.jbehave.core.failures.UUIDExceptionWrapper 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 UUIDExceptionWrapper

use of org.jbehave.core.failures.UUIDExceptionWrapper in project jbehave-core by jbehave.

the class PrintStreamOutputBehaviour method shouldReportEventsToPrintStreamInItalian.

@Test
public void shouldReportEventsToPrintStreamInItalian() {
    // Given
    UUIDExceptionWrapper exception = new UUIDExceptionWrapper(new RuntimeException("Lasciate in pace i miei soldi!"));
    OutputStream out = new ByteArrayOutputStream();
    LocalizedKeywords keywords = new LocalizedKeywords(Locale.ITALIAN);
    StoryReporter reporter = new TxtOutput(new PrintStream(out), new Properties(), keywords, true);
    // When
    reporter.successful("Dato che ho un saldo di $50");
    reporter.successful("Quando richiedo $20");
    reporter.failed("Quando chiedo a Liz un prestito di $100", exception);
    reporter.pending("Allora dovrei avere un saldo di $30");
    reporter.notPerformed("Allora dovrei avere $20");
    // Then
    String expected = "Dato che ho un saldo di $50\n" + "Quando richiedo $20\n" + "Quando chiedo a Liz un prestito di $100 (FALLITO)\n" + "(java.lang.RuntimeException: Lasciate in pace i miei soldi!)\n" + "Allora dovrei avere un saldo di $30 (IN SOSPESO)\n" + "Allora dovrei avere $20 (NON ESEGUITO)\n";
    assertThat(dos2unix(out.toString()), equalTo(expected));
}
Also used : LocalizedKeywords(org.jbehave.core.i18n.LocalizedKeywords) Properties(java.util.Properties) UUIDExceptionWrapper(org.jbehave.core.failures.UUIDExceptionWrapper) Test(org.junit.Test)

Example 4 with UUIDExceptionWrapper

use of org.jbehave.core.failures.UUIDExceptionWrapper in project jbehave-core by jbehave.

the class PrintStreamOutputBehaviour method shouldSuppressStackTraceForKnownFailure.

@Test
public void shouldSuppressStackTraceForKnownFailure() {
    // Given
    final OutputStream out = new ByteArrayOutputStream();
    PrintStreamFactory factory = new PrintStreamFactory() {

        public PrintStream createPrintStream() {
            return new PrintStream(out);
        }
    };
    TxtOutput reporter = new TxtOutput(factory.createPrintStream(), new Properties(), new LocalizedKeywords(), true);
    reporter.failed("Then I should have a balance of $30", new UUIDExceptionWrapper(new MyKnownFailure()));
    reporter.afterScenario();
    assertThat(dos2unix(out.toString()), equalTo("Then I should have a balance of $30 (FAILED)\n" + "(org.jbehave.core.reporters.PrintStreamOutputBehaviour$MyKnownFailure)\n\n" + ""));
}
Also used : LocalizedKeywords(org.jbehave.core.i18n.LocalizedKeywords) Properties(java.util.Properties) UUIDExceptionWrapper(org.jbehave.core.failures.UUIDExceptionWrapper) Test(org.junit.Test)

Example 5 with UUIDExceptionWrapper

use of org.jbehave.core.failures.UUIDExceptionWrapper in project jbehave-core by jbehave.

the class PrintStreamOutputBehaviour method shouldReportFailureTraceWhenToldToDoSo.

@Test
public void shouldReportFailureTraceWhenToldToDoSo() {
    // Given
    UUIDExceptionWrapper exception = new UUIDExceptionWrapper(new RuntimeException("Leave my money alone!"));
    OutputStream stackTrace = new ByteArrayOutputStream();
    exception.getCause().printStackTrace(new PrintStream(stackTrace));
    OutputStream out = new ByteArrayOutputStream();
    TxtOutput reporter = new TxtOutput(new PrintStream(out), new Properties(), new LocalizedKeywords(), true);
    // When
    reporter.beforeScenario(new Scenario("A title", Meta.EMPTY));
    reporter.successful("Given I have a balance of $50");
    reporter.successful("When I request $20");
    reporter.failed("When I ask Liz for a loan of $100", exception);
    reporter.pending("Then I should have a balance of $30");
    reporter.notPerformed("Then I should have $20");
    reporter.afterScenario();
    // Then
    String expected = "Scenario: A title\n" + "Given I have a balance of $50\n" + "When I request $20\n" + "When I ask Liz for a loan of $100 (FAILED)\n" + "(java.lang.RuntimeException: Leave my money alone!)\n" + "Then I should have a balance of $30 (PENDING)\n" + "Then I should have $20 (NOT PERFORMED)\n" + "\n";
    String actual = dos2unix(out.toString());
    assertThat(actual, containsString(expected));
    assertThat(actual, containsString("at org.jbehave.core.reporters.PrintStreamOutputBehaviour.shouldReportFailureTraceWhenToldToDoSo("));
    // Given
    out = new ByteArrayOutputStream();
    reporter = new TxtOutput(new PrintStream(out));
    // When
    reporter.beforeScenario(new Scenario("A title", Meta.EMPTY));
    reporter.successful("Given I have a balance of $50");
    reporter.successful("When I request $20");
    reporter.failed("When I ask Liz for a loan of $100", exception);
    reporter.pending("Then I should have a balance of $30");
    reporter.notPerformed("Then I should have $20");
    reporter.afterScenario();
    // Then
    assertThat(out.toString().contains(stackTrace.toString()), is(false));
}
Also used : LocalizedKeywords(org.jbehave.core.i18n.LocalizedKeywords) Properties(java.util.Properties) UUIDExceptionWrapper(org.jbehave.core.failures.UUIDExceptionWrapper) Scenario(org.jbehave.core.model.Scenario) Test(org.junit.Test)

Aggregations

UUIDExceptionWrapper (org.jbehave.core.failures.UUIDExceptionWrapper)24 Test (org.junit.Test)18 LocalizedKeywords (org.jbehave.core.i18n.LocalizedKeywords)7 Story (org.jbehave.core.model.Story)7 Properties (java.util.Properties)5 OutcomesTable (org.jbehave.core.model.OutcomesTable)5 OutcomesFailed (org.jbehave.core.model.OutcomesTable.OutcomesFailed)5 ExamplesTable (org.jbehave.core.model.ExamplesTable)4 Meta (org.jbehave.core.model.Meta)4 Scenario (org.jbehave.core.model.Scenario)4 Matchers.containsString (org.hamcrest.Matchers.containsString)3 GivenStories (org.jbehave.core.model.GivenStories)3 InOrder (org.mockito.InOrder)3 Date (java.util.Date)2 HashMap (java.util.HashMap)2 LoadFromClasspath (org.jbehave.core.io.LoadFromClasspath)2 GivenStory (org.jbehave.core.model.GivenStory)2 TableTransformers (org.jbehave.core.model.TableTransformers)2 RegexStepMatcher (org.jbehave.core.parsers.RegexStepMatcher)2 StepMatcher (org.jbehave.core.parsers.StepMatcher)2