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"));
}
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;
}
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));
}
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));
}
Aggregations