Skip to content

Commit

Permalink
JBEHAVE-802: Some template-generated reports are invalid.
Browse files Browse the repository at this point in the history
fixed a few additional xml errors in ftl, pendingMethods was below the story tag, if a method contains <>, encoding was missing, closing fields tag was wrong.
Added test with proper pending methods, moved pendingMethods call before afterStory since it was not showing up otherwise.
Added xml validated with xmlunit before comparing strings, this gives nicer error messages if the document is not well-formed
  • Loading branch information
alexlehm committed Jul 27, 2012
1 parent 1d1b89b commit 174380b
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 7 deletions.
6 changes: 6 additions & 0 deletions jbehave-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@
<version>1</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>xmlunit</groupId>
<artifactId>xmlunit</artifactId>
<version>1.3</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@
</div> <!-- end story -->
<#if story.getPendingMethods()??>
<#list story.getPendingMethods() as method>
<div><pre class="pending">${method}</pre></div>
<div><pre class="pending">${method?html}</pre></div>
</#list>
</#if>
</body>
Expand Down
6 changes: 3 additions & 3 deletions jbehave-core/src/main/resources/ftl/jbehave-xml-output.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
<#list fields as field>
<field>${field?xml}</field>
</#list>
<fields>
</fields>
<#list outcomes as outcome>
<#assign isVerified=outcome.isVerified()?string>
<#if isVerified == "true"> <#assign verified="verified"><#else><#assign verified="notVerified"></#if>
Expand Down Expand Up @@ -102,10 +102,10 @@ ${formattedStep?xml}<#if step.getTable()??> <parameter><@renderTable step.getTab
<#if story.isCancelled()?string == 'true'>
<cancelled keyword="${keywords.storyCancelled}" durationKeyword="${keywords.duration}" durationInSecs="${story.storyDuration.durationInSecs}"/>
</#if>
</story>
<#if story.getPendingMethods()??>
<#list story.getPendingMethods() as method>
<pendingMethod>${method}</pendingMethod>
<pendingMethod>${method?xml}</pendingMethod>
</#list>
</#if>
</story>

Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.util.Properties;

import org.apache.commons.io.IOUtils;
import org.custommonkey.xmlunit.XMLUnit;
import org.jbehave.core.failures.RestartingScenarioFailure;
import org.jbehave.core.failures.UUIDExceptionWrapper;
import org.jbehave.core.i18n.LocalizedKeywords;
Expand All @@ -20,6 +21,7 @@
import org.jbehave.core.model.Story;
import org.jbehave.core.model.StoryDuration;
import org.junit.Test;
import org.xml.sax.SAXException;

import static java.util.Arrays.asList;

Expand All @@ -45,7 +47,7 @@ public void shouldReportEventsToHtmlOutput() throws IOException {
}

@Test
public void shouldReportEventsToXmlOutput() throws IOException {
public void shouldReportEventsToXmlOutput() throws IOException, SAXException {
// Given
File file = new File("target/story.xml");
StoryReporter reporter = new XmlTemplateOuput(file, new LocalizedKeywords());
Expand All @@ -56,6 +58,12 @@ public void shouldReportEventsToXmlOutput() throws IOException {
// Then
String expected = IOUtils.toString(new FileReader(new File("src/test/resources/story.xml")));
String out = IOUtils.toString(new FileReader(file));

// will throw SAXException if the xml file is not well-formed
XMLUnit.buildTestDocument(out);

System.out.println(file);
System.out.println(out);
assertThatOutputIs(out, expected);
}

Expand Down Expand Up @@ -102,13 +110,23 @@ public static void narrateAnInterestingStory(StoryReporter reporter, boolean wit
if (withFailure) {
reporter.failed("Then I should have a balance of $30", new Exception("Expected <30> got <25>"));
} else {
reporter.pending("Then I should have a balance of $30");
reporter.pending("Then I should have a balance of $30");
}
reporter.afterExamples();
reporter.afterScenario();
reporter.storyCancelled(story, new StoryDuration(2, 1));
String method1="@When(\"something \\\"$param\\\"\")\n"
+ "@Pending\n"
+ "public void whenSomething() {\n"
+ " // PENDING\n"
+ "}\n";
String method2="@Then(\"something is <param1>\")\n"
+ "@Pending\n"
+ "public void thenSomethingIsParam1() {\n"
+ " // PENDING\n"
+ "}\n";
reporter.pendingMethods(asList(method1, method2));
reporter.afterStory(givenStory);
reporter.pendingMethods(asList("method1", "method2"));
}

private void assertThatOutputIs(String out, String expected) {
Expand Down

0 comments on commit 174380b

Please sign in to comment.