use of org.jbehave.core.model.GivenStories 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.GivenStories 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);
}
use of org.jbehave.core.model.GivenStories in project jbehave-core by jbehave.
the class RegexStoryParser method findScenarioGivenStories.
private GivenStories findScenarioGivenStories(String scenarioAsText) {
Matcher findingGivenStories = findingScenarioGivenStories().matcher(scenarioAsText);
String givenStories = findingGivenStories.find() ? findingGivenStories.group(1).trim() : NONE;
return new GivenStories(givenStories);
}
use of org.jbehave.core.model.GivenStories in project jbehave-core by jbehave.
the class RegexStoryParserBehaviour method shouldParseStoryWithScenarioContainingParametrisedGivenStories.
@Test
public void shouldParseStoryWithScenarioContainingParametrisedGivenStories() {
String wholeStory = "GivenStories: path/to/one#{0}, path/to/two#{1}, path/to/three#{2}, path/to/four#{a}, path/to/five" + NL + NL + "Given a step" + NL + "Examples:" + NL + "|one|two|" + NL + "|11|12|" + NL + "|21|22|";
Story story = parser.parseStory(wholeStory, storyPath);
Scenario scenario = story.getScenarios().get(0);
GivenStories givenStories = scenario.getGivenStories();
assertThat(givenStories.asString(), equalTo("path/to/one#{0}, path/to/two#{1}, path/to/three#{2}, path/to/four#{a}, path/to/five"));
assertThat(givenStories.toString(), containsString(givenStories.asString()));
assertThat(givenStories.getPaths(), equalTo(asList(// matches first parameters row
"path/to/one#{0}", // matches second parameters row
"path/to/two#{1}", // does not match any parameters row
"path/to/three#{2}", // does not use valid anchor (an int)
"path/to/four#{a}", // does not require parameters
"path/to/five")));
assertThat(givenStories.requireParameters(), equalTo(true));
GivenStory givenStory1 = givenStories.getStories().get(0);
assertThat(givenStory1.hasAnchor(), equalTo(true));
assertThat(givenStory1.getAnchor(), equalTo("0"));
assertThat(givenStory1.getPath(), equalTo("path/to/one"));
assertThat(givenStory1.getParameters().get("one"), equalTo("11"));
assertThat(givenStory1.getParameters().get("two"), equalTo("12"));
GivenStory givenStory2 = givenStories.getStories().get(1);
assertThat(givenStory2.hasAnchor(), equalTo(true));
assertThat(givenStory2.getAnchor(), equalTo("1"));
assertThat(givenStory2.getPath(), equalTo("path/to/two"));
assertThat(givenStory2.getParameters().get("one"), equalTo("21"));
assertThat(givenStory2.getParameters().get("two"), equalTo("22"));
GivenStory givenStory3 = givenStories.getStories().get(2);
assertThat(givenStory3.hasAnchor(), equalTo(true));
assertThat(givenStory3.getAnchor(), equalTo("2"));
assertThat(givenStory3.getPath(), equalTo("path/to/three"));
assertThat(givenStory3.getParameters().size(), equalTo(0));
GivenStory givenStory4 = givenStories.getStories().get(3);
assertThat(givenStory4.hasAnchor(), equalTo(true));
assertThat(givenStory4.getAnchor(), equalTo("a"));
assertThat(givenStory4.getPath(), equalTo("path/to/four"));
assertThat(givenStory4.getParameters().size(), equalTo(0));
GivenStory givenStory5 = givenStories.getStories().get(4);
assertThat(givenStory5.hasAnchor(), equalTo(false));
assertThat(givenStory5.getAnchor(), equalTo(EMPTY));
assertThat(givenStory5.getPath(), equalTo("path/to/five"));
assertThat(givenStory5.getParameters().size(), equalTo(0));
}
use of org.jbehave.core.model.GivenStories in project jbehave-core by jbehave.
the class DelegatingStoryReporterBehaviour method shouldDelegateReporterEvents.
@Test
public void shouldDelegateReporterEvents() {
// Given
StoryReporter delegate = mock(StoryReporter.class);
DelegatingStoryReporter delegator = new DelegatingStoryReporter(delegate);
List<String> givenStoryPaths = asList("path/to/story1", "path/to/story2");
GivenStories givenStories = new GivenStories(StringUtils.join(givenStoryPaths, ","));
ExamplesTable examplesTable = new ExamplesTable("|one|two|\n|1|2|\n");
UUIDExceptionWrapper anException = new UUIDExceptionWrapper(new IllegalArgumentException());
Story story = new Story();
boolean givenStory = false;
Scenario scenario = new Scenario();
String filter = "-some property";
// When
delegator.dryRun();
delegator.beforeStory(story, givenStory);
delegator.storyNotAllowed(story, filter);
delegator.beforeScenario(scenario);
delegator.beforeScenario("My scenario 1");
delegator.scenarioNotAllowed(scenario, filter);
delegator.scenarioMeta(Meta.EMPTY);
delegator.givenStories(givenStoryPaths);
delegator.givenStories(givenStories);
delegator.successful("Given step 1.1");
delegator.ignorable("!-- Then ignore me");
delegator.comment("!-- comment");
delegator.pending("When step 1.2");
delegator.notPerformed("Then step 1.3");
delegator.beforeExamples(asList("Given step <one>", "Then step <two>"), examplesTable);
delegator.example(examplesTable.getRow(0));
delegator.afterExamples();
delegator.afterScenario();
delegator.beforeScenario("My scenario 2");
delegator.successful("Given step 2.1");
delegator.successful("When step 2.2");
delegator.failed("Then step 2.3", anException);
delegator.afterScenario();
delegator.afterStory(givenStory);
// Then
assertThat(delegator.toString(), containsString(delegate.toString()));
InOrder inOrder = inOrder(delegate);
inOrder.verify(delegate).dryRun();
inOrder.verify(delegate).beforeStory(story, givenStory);
inOrder.verify(delegate).storyNotAllowed(story, filter);
inOrder.verify(delegate).beforeScenario(scenario);
inOrder.verify(delegate).beforeScenario("My scenario 1");
inOrder.verify(delegate).scenarioNotAllowed(scenario, filter);
inOrder.verify(delegate).scenarioMeta(Meta.EMPTY);
inOrder.verify(delegate).givenStories(givenStoryPaths);
inOrder.verify(delegate).givenStories(givenStories);
inOrder.verify(delegate).successful("Given step 1.1");
inOrder.verify(delegate).ignorable("!-- Then ignore me");
inOrder.verify(delegate).comment("!-- comment");
inOrder.verify(delegate).pending("When step 1.2");
inOrder.verify(delegate).notPerformed("Then step 1.3");
inOrder.verify(delegate).beforeExamples(asList("Given step <one>", "Then step <two>"), examplesTable);
inOrder.verify(delegate).example(examplesTable.getRow(0));
inOrder.verify(delegate).afterExamples();
inOrder.verify(delegate).afterScenario();
inOrder.verify(delegate).beforeScenario("My scenario 2");
inOrder.verify(delegate).successful("Given step 2.1");
inOrder.verify(delegate).successful("When step 2.2");
inOrder.verify(delegate).failed("Then step 2.3", anException);
inOrder.verify(delegate).afterScenario();
inOrder.verify(delegate).afterStory(givenStory);
}
Aggregations