Search in sources :

Example 6 with UUIDExceptionWrapper

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

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

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

the class StepResultBehaviour method shouldDescribeResultToReporterWithParameterValuesWhenAvailable.

@Test
public void shouldDescribeResultToReporterWithParameterValuesWhenAvailable() {
    // Given
    StoryReporter reporter = mock(StoryReporter.class);
    // When
    String successful = "Given that a step is pending or failing";
    successful("Given that a step is $pending or $failing").withParameterValues(successful).describeTo(reporter);
    String pending = "When a step is performed";
    pending("When a step is $performed").withParameterValues(pending).describeTo(reporter);
    String notPerformed = "Then the step should describe itself properly to reporters";
    notPerformed("Then the step should $describe itself properly to reporters").withParameterValues(notPerformed).describeTo(reporter);
    String failed = "And any errors should appear at the end of the story";
    UUIDExceptionWrapper cause = new UUIDExceptionWrapper(new IllegalStateException());
    failed("And any errors should $appear at the end of the story", cause).withParameterValues(failed).describeTo(reporter);
    // Then
    verify(reporter).successful(successful);
    verify(reporter).pending(pending);
    verify(reporter).notPerformed(notPerformed);
    verify(reporter).failed(failed, cause);
}
Also used : StoryReporter(org.jbehave.core.reporters.StoryReporter) Matchers.containsString(org.hamcrest.Matchers.containsString) UUIDExceptionWrapper(org.jbehave.core.failures.UUIDExceptionWrapper) Test(org.junit.Test)

Example 9 with UUIDExceptionWrapper

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

the class StepsBehaviour method shouldProvideStepsToBeNotPerformedAfterScenarioUponOutcome.

@Test
public void shouldProvideStepsToBeNotPerformedAfterScenarioUponOutcome() {
    MultipleAliasesSteps steps = new MultipleAliasesSteps();
    ScenarioType scenarioType = ScenarioType.NORMAL;
    List<BeforeOrAfterStep> beforeAfterScenario = steps.listBeforeOrAfterScenario(scenarioType);
    assertThat(beforeAfterScenario.size(), equalTo(4));
    beforeAfterScenario.get(0).createStep().doNotPerform(null);
    assertThat(steps.beforeNormalScenario, is(true));
    Meta storyAndScenarioMeta = null;
    UUIDExceptionWrapper failure = new UUIDExceptionWrapper();
    // uponOutcome=ANY
    beforeAfterScenario.get(1).createStepUponOutcome(storyAndScenarioMeta).doNotPerform(failure);
    assertThat(steps.afterNormalScenario, is(true));
    // uponOutcome=SUCCESS
    beforeAfterScenario.get(2).createStepUponOutcome(storyAndScenarioMeta).doNotPerform(failure);
    assertThat(steps.afterSuccessfulScenario, is(false));
    // uponOutcome=FAILURE
    beforeAfterScenario.get(3).createStepUponOutcome(storyAndScenarioMeta).doNotPerform(failure);
    assertThat(steps.afterFailedScenario, is(true));
}
Also used : Meta(org.jbehave.core.model.Meta) ScenarioType(org.jbehave.core.annotations.ScenarioType) UUIDExceptionWrapper(org.jbehave.core.failures.UUIDExceptionWrapper) Test(org.junit.Test)

Example 10 with UUIDExceptionWrapper

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

the class MarkUnmatchedStepsAsPendingBehaviour method shouldInvokeBeforeOrAfterStoryWithParameterAndException.

@Test
public void shouldInvokeBeforeOrAfterStoryWithParameterAndException() throws Exception {
    BeforeOrAfterStoryWithParameterAndExceptionSteps steps = new BeforeOrAfterStoryWithParameterAndExceptionSteps();
    Story story = mock(Story.class);
    when(story.getMeta()).thenReturn(beforeAndAfterMeta());
    List<Step> beforeSteps = stepCollector.collectBeforeOrAfterStorySteps(asList((CandidateSteps) steps), story, Stage.BEFORE, false);
    UUIDExceptionWrapper failureOccurred = new UUIDExceptionWrapper();
    beforeSteps.get(0).doNotPerform(failureOccurred);
    assertThat(steps.value, equalTo("before"));
    assertThat(steps.exception, equalTo(failureOccurred));
    List<Step> afterSteps = stepCollector.collectBeforeOrAfterStorySteps(asList((CandidateSteps) steps), story, Stage.AFTER, false);
    failureOccurred = new UUIDExceptionWrapper();
    afterSteps.get(0).doNotPerform(failureOccurred);
    assertThat(steps.value, equalTo("after"));
    assertThat(steps.exception, equalTo(failureOccurred));
}
Also used : PendingStep(org.jbehave.core.steps.StepCreator.PendingStep) Story(org.jbehave.core.model.Story) UUIDExceptionWrapper(org.jbehave.core.failures.UUIDExceptionWrapper) 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