Skip to content

Commit

Permalink
JBEHAVE-816: refactor methods narrateAnInterestingStory into one method
Browse files Browse the repository at this point in the history
moved narrateAnInterestingStory and narrateAnInterestingStoryNotAllowedByFilter to new class StoryNarrator and merged the different versions, fixed test results for the different tests to match.
  • Loading branch information
alexlehm committed Aug 11, 2012
1 parent aef1a65 commit 033acf8
Show file tree
Hide file tree
Showing 8 changed files with 275 additions and 297 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public String getMetaFilter() {
when(builder.pathResolver()).thenReturn(pathResolver);

// When
PrintStreamOutputBehaviour.narrateAnInterestingStory(crossReference.createStoryReporter(factory, builder), true);
StoryNarrator.narrateAnInterestingStory(crossReference.createStoryReporter(factory, builder), true);
crossReference.getStepMonitor().stepMatchesPattern("a", true, new StepPattern(StepType.GIVEN, "(def)", "[abc]"), Object.class.getDeclaredMethods()[0], new Object());

// generate XML and JSON
Expand Down Expand Up @@ -111,7 +111,7 @@ public String getMetaFilter() {
" <usages>\n" +
" <use>\n" +
" <story>/path/to/story</story>\n" +
" <scenario>I ask for a loan</scenario>\n" +
" <scenario>Parametrised Scenario</scenario>\n" +
" <step>a</step>\n" +
" </use>\n" +
" </usages>\n" +
Expand Down Expand Up @@ -149,7 +149,7 @@ public String getMetaFilter() {
" 'usages': [\n" +
" {\n" +
" 'story': '/path/to/story',\n" +
" 'scenario': 'I ask for a loan',\n" +
" 'scenario': 'Parametrised Scenario',\n" +
" 'step': 'a'\n" +
" }\n" +
" ]\n" +
Expand Down Expand Up @@ -205,7 +205,7 @@ public String getMetaFilter() {
when(builder.pathResolver()).thenReturn(pathResolver);

// When
PrintStreamOutputBehaviour.narrateAnInterestingStory(crossReference.createStoryReporter(factory, builder), true);
StoryNarrator.narrateAnInterestingStory(crossReference.createStoryReporter(factory, builder), true);
crossReference.getStepMonitor().stepMatchesPattern("a", true, new StepPattern(StepType.GIVEN, "(def)", "[abc]"), Object.class.getDeclaredMethods()[0], new Object());

// generate XML and JSON
Expand Down Expand Up @@ -248,7 +248,7 @@ public String getMetaFilter() {
" <usages>\n" +
" <use>\n" +
" <story>/path/to/story</story>\n" +
" <scenario>I ask for a loan</scenario>\n" +
" <scenario>Parametrised Scenario</scenario>\n" +
" <step>a</step>\n" +
" </use>\n" +
" </usages>\n" +
Expand Down Expand Up @@ -307,7 +307,7 @@ public String getMetaFilter() {
when(builder.pathResolver()).thenReturn(pathResolver);

// When
PrintStreamOutputBehaviour.narrateAnInterestingStory(crossReference.createStoryReporter(factory, builder), true);
StoryNarrator.narrateAnInterestingStory(crossReference.createStoryReporter(factory, builder), true);
crossReference.getStepMonitor().stepMatchesPattern("a", true, new StepPattern(StepType.GIVEN, "(def)", "[abc]"), Object.class.getDeclaredMethods()[0], new Object());

// generate XML and JSON
Expand Down Expand Up @@ -346,7 +346,7 @@ public String getMetaFilter() {
" 'usages': [\n" +
" {\n" +
" 'story': '/path/to/story',\n" +
" 'scenario': 'I ask for a loan',\n" +
" 'scenario': 'Parametrised Scenario',\n" +
" 'step': 'a'\n" +
" }\n" +
" ]\n" +
Expand Down Expand Up @@ -404,7 +404,7 @@ protected void aliasForXRefRoot(XStream xstream) {
when(builder.pathResolver()).thenReturn(pathResolver);

// When
PrintStreamOutputBehaviour.narrateAnInterestingStory(crossReference.createStoryReporter(factory, builder), true);
StoryNarrator.narrateAnInterestingStory(crossReference.createStoryReporter(factory, builder), true);
crossReference.getStepMonitor().stepMatchesPattern("a", true, new StepPattern(StepType.GIVEN, "(def)", "[abc]"), Object.class.getDeclaredMethods()[0], new Object());

// generate XML and JSON
Expand Down Expand Up @@ -446,7 +446,7 @@ protected void aliasForXRefRoot(XStream xstream) {
" <usages>\n" +
" <use>\n" +
" <story>/path/to/story</story>\n" +
" <scenario>I ask for a loan</scenario>\n" +
" <scenario>Parametrised Scenario</scenario>\n" +
" <step>a</step>\n" +
" </use>\n" +
" </usages>\n" +
Expand Down Expand Up @@ -487,7 +487,7 @@ protected void aliasForXRefRoot(XStream xstream) {
" 'usages': [\n" +
" {\n" +
" 'story': '/path/to/story',\n" +
" 'scenario': 'I ask for a loan',\n" +
" 'scenario': 'Parametrised Scenario',\n" +
" 'step': 'a'\n" +
" }\n" +
" ]\n" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,43 +39,8 @@ public void afterStory(boolean givenStory) {
}

};
narrateAnInterestingStory(reporter);
StoryNarrator.narrateAnInterestingStory(reporter, false);
assertThat(out.toString(), Matchers.equalTo("beforeStory" + NL + "afterStory" + NL));
}


private void narrateAnInterestingStory(StoryReporter reporter) {
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();
reporter.beforeStory(story, false);

// successful scenario
reporter.beforeScenario("A successful scenario");
reporter.successful("Given I have a balance of $50");
reporter.ignorable("!-- A comment");
reporter.successful("When I request $20");
reporter.successful("When I ask Liz for a loan of $100");
reporter.afterScenario();

// failing scenario
reporter.beforeScenario("A failing scenario");
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.pending("Then I should have a balance of $30");
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();
reporter.afterStory(false);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public void shouldCollectStoryStatistics() {
@Test
public void shouldCollectStoryStatisticsWhenStoryNotAllowedByFilter() {
// When
narrateAnInterestingStoryNotAllowedByFilter(true);
StoryNarrator.narrateAnInterestingStoryNotAllowedByFilter(reporter, true);

// Then
String statistics = out.toString();
Expand All @@ -84,7 +84,7 @@ public void shouldCollectStoryStatisticsWhenStoryNotAllowedByFilter() {
@Test
public void shouldCollectStoryStatisticsWhenScenariosNotAllowedByFilter() {
// When
narrateAnInterestingStoryNotAllowedByFilter(false);
StoryNarrator.narrateAnInterestingStoryNotAllowedByFilter(reporter, false);

// Then
String statistics = out.toString();
Expand Down

0 comments on commit 033acf8

Please sign in to comment.