use of org.jbehave.core.model.Scenario in project jbehave-core by jbehave.
the class RegexStoryParserBehaviour method shouldParseStoryWithLifecycle.
@Test
public void shouldParseStoryWithLifecycle() {
String wholeStory = "Lifecycle: " + NL + "Before:" + NL + NL + "Given a step before each scenario" + NL + "And another before step" + NL + "After:" + NL + NL + "Given a step after each scenario" + NL + "And another after step" + NL + "Scenario:" + NL + "Given a scenario";
Story story = parser.parseStory(wholeStory, storyPath);
List<String> beforeSteps = story.getLifecycle().getBeforeSteps();
assertThat(beforeSteps.get(0), equalTo("Given a step before each scenario"));
assertThat(beforeSteps.get(1), equalTo("And another before step"));
List<String> afterSteps = story.getLifecycle().getAfterSteps();
assertThat(afterSteps.get(0), equalTo("Given a step after each scenario"));
assertThat(afterSteps.get(1), equalTo("And another after step"));
Scenario scenario = story.getScenarios().get(0);
List<String> steps = scenario.getSteps();
assertThat(steps.get(0), equalTo("Given a scenario"));
}
use of org.jbehave.core.model.Scenario 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);
}
use of org.jbehave.core.model.Scenario 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));
}
use of org.jbehave.core.model.Scenario 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);
}
use of org.jbehave.core.model.Scenario in project jbehave-core by jbehave.
the class GherkinStoryParserBehaviour method shouldParseStoryWithTabularParameter.
@Test
public void shouldParseStoryWithTabularParameter() throws IOException {
String storyAsText = "Feature: Hello Car\n" + "Scenario: Car can drive\n" + "Given I have a car\n" + "Then I can drive them according to:\n" + "| wheels | can_drive |\n" + "| 1 | false |\n" + "| 2 | false |\n" + "| 3 | false |\n" + "| 4 | true |\n";
Story story = storyParser.parseStory(storyAsText);
assertThat(story.getDescription().asString(), equalTo("Hello Car"));
List<Scenario> scenarios = story.getScenarios();
assertThat(scenarios.size(), equalTo(1));
Scenario scenario = scenarios.get(0);
List<String> steps = scenario.getSteps();
assertThat(scenario.getTitle(), equalTo("Car can drive"));
assertThat(steps.size(), equalTo(2));
assertThat(steps.get(0), equalTo("Given I have a car"));
assertThat(steps.get(1), equalTo("Then I can drive them according to:\n" + "|wheels|can_drive|\n" + "|1|false|\n" + "|2|false|\n" + "|3|false|\n" + "|4|true|"));
}
Aggregations