Search in sources :

Example 6 with Lifecycle

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

the class RegexStoryParserBehaviour method shouldParseStoryWithMetaAndLifecycle.

@Test
public void shouldParseStoryWithMetaAndLifecycle() {
    String wholeStory = "Meta: @skip @theme parsing" + NL + "Lifecycle:" + NL + "Before:" + NL + "Given a step before each scenario" + NL + "And another before step" + NL + "Scenario: A scenario" + NL + "Meta: @author Mauro" + NL + "Given a step " + NL + "Scenario: Another scenario" + NL + "Meta: @author Paul" + NL + "Given another step ";
    Story story = parser.parseStory(wholeStory, storyPath);
    assertThat(story.getPath(), equalTo(storyPath));
    Meta storyMeta = story.getMeta();
    assertThat(storyMeta.getProperty("theme"), equalTo("parsing"));
    assertThat(storyMeta.getProperty("skip"), equalTo(EMPTY));
    assertThat(storyMeta.getProperty("unknown"), equalTo(EMPTY));
    Lifecycle lifecycle = story.getLifecycle();
    assertThat(lifecycle.getBeforeSteps().size(), equalTo(2));
    List<Scenario> scenarios = story.getScenarios();
    assertThat(scenarios.get(0).getTitle(), equalTo("A scenario"));
    assertThat(scenarios.get(0).getMeta().getProperty("author"), equalTo("Mauro"));
    assertThat(scenarios.get(1).getTitle(), equalTo("Another scenario"));
    assertThat(scenarios.get(1).getMeta().getProperty("author"), equalTo("Paul"));
}
Also used : Meta(org.jbehave.core.model.Meta) Lifecycle(org.jbehave.core.model.Lifecycle) Matchers.containsString(org.hamcrest.Matchers.containsString) GivenStory(org.jbehave.core.model.GivenStory) Story(org.jbehave.core.model.Story) Scenario(org.jbehave.core.model.Scenario) Test(org.junit.Test)

Example 7 with Lifecycle

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

the class RegexStoryParser method parseStory.

public Story parseStory(String storyAsText, String storyPath) {
    Description description = parseDescriptionFrom(storyAsText);
    Meta meta = parseStoryMetaFrom(storyAsText);
    Narrative narrative = parseNarrativeFrom(storyAsText);
    GivenStories givenStories = parseGivenStories(storyAsText);
    Lifecycle lifecycle = parseLifecycle(storyAsText);
    List<Scenario> scenarios = parseScenariosFrom(storyAsText);
    Story story = new Story(storyPath, description, meta, narrative, givenStories, lifecycle, scenarios);
    if (storyPath != null) {
        story.namedAs(new File(storyPath).getName());
    }
    return story;
}
Also used : GivenStories(org.jbehave.core.model.GivenStories) Meta(org.jbehave.core.model.Meta) Description(org.jbehave.core.model.Description) Narrative(org.jbehave.core.model.Narrative) Lifecycle(org.jbehave.core.model.Lifecycle) Story(org.jbehave.core.model.Story) File(java.io.File) Scenario(org.jbehave.core.model.Scenario)

Example 8 with Lifecycle

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

the class MarkUnmatchedStepsAsPendingBehaviour method shouldCreateExecutableStepsUponOutcomeAndScope.

@Test
public void shouldCreateExecutableStepsUponOutcomeAndScope() {
    // Given
    StepCandidate anyCandidate = mock(StepCandidate.class, "anyCandidate");
    StepCandidate successCandidate = mock(StepCandidate.class, "successCandidate");
    StepCandidate failureCandidate = mock(StepCandidate.class, "failureCandidate");
    Step anyStep = mock(Step.class, "anyStep");
    Step successStep = mock(Step.class, "successStep");
    Step failureStep = mock(Step.class, "failureStep");
    String myAnyStep = "my any step";
    when(anyCandidate.matches(myAnyStep)).thenReturn(true);
    when(anyCandidate.createMatchedStepUponOutcome(myAnyStep, parameters, Outcome.ANY)).thenReturn(anyStep);
    when(successCandidate.isAndStep(myAnyStep)).thenReturn(false);
    String mySuccessStep = "my success step";
    when(successCandidate.matches(mySuccessStep)).thenReturn(true);
    when(successCandidate.isAndStep(mySuccessStep)).thenReturn(false);
    when(successCandidate.createMatchedStepUponOutcome(mySuccessStep, parameters, Outcome.SUCCESS)).thenReturn(successStep);
    String myFailureStep = "my failure step";
    when(successCandidate.matches(myFailureStep)).thenReturn(true);
    when(successCandidate.isAndStep(myFailureStep)).thenReturn(false);
    when(successCandidate.createMatchedStepUponOutcome(myFailureStep, parameters, Outcome.FAILURE)).thenReturn(failureStep);
    List<CandidateSteps> steps = mockCandidateSteps(anyCandidate, successCandidate, failureCandidate);
    Scope scope = Scope.STORY;
    Lifecycle lifecycle = new Lifecycle(Arrays.<Lifecycle.Steps>asList(), asList(new Lifecycle.Steps(scope, Outcome.ANY, asList(myAnyStep)), new Lifecycle.Steps(scope, Outcome.SUCCESS, asList(mySuccessStep)), new Lifecycle.Steps(scope, Outcome.FAILURE, asList(myFailureStep))));
    // When
    List<Step> executableSteps = stepCollector.collectLifecycleSteps(steps, lifecycle, Meta.EMPTY, Stage.AFTER, scope);
    // Then
    assertThat(executableSteps.size(), equalTo(3));
    assertThat(executableSteps.get(0), equalTo(anyStep));
    assertThat(executableSteps.get(1), equalTo(successStep));
    assertThat(executableSteps.get(2), equalTo(failureStep));
}
Also used : Lifecycle(org.jbehave.core.model.Lifecycle) PendingStep(org.jbehave.core.steps.StepCreator.PendingStep) Test(org.junit.Test)

Example 9 with Lifecycle

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

the class MarkUnmatchedStepsAsPendingBehaviour method shouldCreateExecutableStepsUponOutcome.

@Test
public void shouldCreateExecutableStepsUponOutcome() {
    // Given
    StepCandidate anyCandidate = mock(StepCandidate.class, "anyCandidate");
    StepCandidate successCandidate = mock(StepCandidate.class, "successCandidate");
    StepCandidate failureCandidate = mock(StepCandidate.class, "failureCandidate");
    Step anyStep = mock(Step.class, "anyStep");
    Step successStep = mock(Step.class, "successStep");
    Step failureStep = mock(Step.class, "failureStep");
    String myAnyStep = "my any step";
    when(anyCandidate.matches(myAnyStep)).thenReturn(true);
    when(anyCandidate.createMatchedStepUponOutcome(myAnyStep, parameters, Outcome.ANY)).thenReturn(anyStep);
    when(successCandidate.isAndStep(myAnyStep)).thenReturn(false);
    String mySuccessStep = "my success step";
    when(successCandidate.matches(mySuccessStep)).thenReturn(true);
    when(successCandidate.isAndStep(mySuccessStep)).thenReturn(false);
    when(successCandidate.createMatchedStepUponOutcome(mySuccessStep, parameters, Outcome.SUCCESS)).thenReturn(successStep);
    String myFailureStep = "my failure step";
    when(successCandidate.matches(myFailureStep)).thenReturn(true);
    when(successCandidate.isAndStep(myFailureStep)).thenReturn(false);
    when(successCandidate.createMatchedStepUponOutcome(myFailureStep, parameters, Outcome.FAILURE)).thenReturn(failureStep);
    List<CandidateSteps> steps = mockCandidateSteps(anyCandidate, successCandidate, failureCandidate);
    Lifecycle lifecycle = new Lifecycle(Arrays.<Lifecycle.Steps>asList(), asList(new Lifecycle.Steps(Outcome.ANY, asList(myAnyStep)), new Lifecycle.Steps(Outcome.SUCCESS, asList(mySuccessStep)), new Lifecycle.Steps(Outcome.FAILURE, asList(myFailureStep))));
    // When
    List<Step> executableSteps = stepCollector.collectLifecycleSteps(steps, lifecycle, Meta.EMPTY, Stage.AFTER, Scope.SCENARIO);
    // Then
    assertThat(executableSteps.size(), equalTo(3));
    assertThat(executableSteps.get(0), equalTo(anyStep));
    assertThat(executableSteps.get(1), equalTo(successStep));
    assertThat(executableSteps.get(2), equalTo(failureStep));
}
Also used : Lifecycle(org.jbehave.core.model.Lifecycle) PendingStep(org.jbehave.core.steps.StepCreator.PendingStep) Test(org.junit.Test)

Aggregations

Lifecycle (org.jbehave.core.model.Lifecycle)9 Test (org.junit.Test)6 Scenario (org.jbehave.core.model.Scenario)5 Story (org.jbehave.core.model.Story)5 Matchers.containsString (org.hamcrest.Matchers.containsString)4 GivenStory (org.jbehave.core.model.GivenStory)4 Meta (org.jbehave.core.model.Meta)3 LocalizedKeywords (org.jbehave.core.i18n.LocalizedKeywords)2 PendingStep (org.jbehave.core.steps.StepCreator.PendingStep)2 File (java.io.File)1 Matcher (java.util.regex.Matcher)1 Keywords (org.jbehave.core.configuration.Keywords)1 LoadFromClasspath (org.jbehave.core.io.LoadFromClasspath)1 Description (org.jbehave.core.model.Description)1 ExamplesTable (org.jbehave.core.model.ExamplesTable)1 GivenStories (org.jbehave.core.model.GivenStories)1 Steps (org.jbehave.core.model.Lifecycle.Steps)1 Narrative (org.jbehave.core.model.Narrative)1 TableTransformers (org.jbehave.core.model.TableTransformers)1