Search in sources :

Example 6 with LocalizedKeywords

use of org.jbehave.core.i18n.LocalizedKeywords 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 7 with LocalizedKeywords

use of org.jbehave.core.i18n.LocalizedKeywords 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 8 with LocalizedKeywords

use of org.jbehave.core.i18n.LocalizedKeywords 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 9 with LocalizedKeywords

use of org.jbehave.core.i18n.LocalizedKeywords in project jbehave-core by jbehave.

the class PrintStreamOutputBehaviour method shouldOutputStoryJson.

@Test
public void shouldOutputStoryJson() throws IOException, SAXException {
    // Given
    String name = "stream-story.json";
    File file = new File("target/" + name);
    StoryReporter reporter = new JsonOutput(new FilePrintStreamFactory.FilePrintStream(file, false), new LocalizedKeywords());
    // When
    StoryNarrator.narrateAnInterestingStory(reporter, false);
    // Then
    assertFileOutputIsSameAs(file, name);
    validateFileOutput(file);
}
Also used : LocalizedKeywords(org.jbehave.core.i18n.LocalizedKeywords) Test(org.junit.Test)

Example 10 with LocalizedKeywords

use of org.jbehave.core.i18n.LocalizedKeywords 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

LocalizedKeywords (org.jbehave.core.i18n.LocalizedKeywords)35 Test (org.junit.Test)23 Properties (java.util.Properties)14 MostUsefulConfiguration (org.jbehave.core.configuration.MostUsefulConfiguration)10 Locale (java.util.Locale)8 Keywords (org.jbehave.core.configuration.Keywords)8 SimpleDateFormat (java.text.SimpleDateFormat)7 UUIDExceptionWrapper (org.jbehave.core.failures.UUIDExceptionWrapper)7 TableTransformers (org.jbehave.core.model.TableTransformers)7 Configuration (org.jbehave.core.configuration.Configuration)6 LoadFromClasspath (org.jbehave.core.io.LoadFromClasspath)6 RegexPrefixCapturingPatternParser (org.jbehave.core.parsers.RegexPrefixCapturingPatternParser)6 SilentlyAbsorbingFailure (org.jbehave.core.failures.SilentlyAbsorbingFailure)5 LoadFromURL (org.jbehave.core.io.LoadFromURL)5 StoryReporterBuilder (org.jbehave.core.reporters.StoryReporterBuilder)5 ParameterConverters (org.jbehave.core.steps.ParameterConverters)5 RegexStoryParser (org.jbehave.core.parsers.RegexStoryParser)4 ArrayList (java.util.ArrayList)3 StoryLocation (org.jbehave.core.io.StoryLocation)3 ExamplesTableFactory (org.jbehave.core.model.ExamplesTableFactory)3