Skip to content

Commit

Permalink
Merge pull request #134 from ebjwc/gh-76-1.4.0
Browse files Browse the repository at this point in the history
Make use of Spock Tags and Attachments
  • Loading branch information
renatoathaydes authored Mar 26, 2018
2 parents 84a7352 + b908bc5 commit 0b9b84c
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@ import com.athaydes.spockframework.report.vivid.BlockCode
import com.athaydes.spockframework.report.vivid.SpecSourceCodeReader
import groovy.util.logging.Slf4j
import groovy.xml.MarkupBuilder
import org.spockframework.runtime.model.Attachment
import org.spockframework.runtime.model.BlockInfo
import org.spockframework.runtime.model.FeatureInfo
import org.spockframework.runtime.model.IterationInfo
import org.spockframework.runtime.model.SpecElementInfo
import org.spockframework.runtime.model.Tag
import spock.lang.Ignore
import spock.lang.Issue
import spock.lang.PendingFeature
Expand Down Expand Up @@ -171,22 +174,15 @@ class HtmlReportCreator extends AbstractHtmlCreator<SpecData>
if ( narrative ) {
builder.pre( 'class': 'narrative', narrative )
}
def issues = Utils.specAnnotation( data, Issue )
if ( issues ) {
writeIssuesOrSees( builder, issues, 'Issues:' )
}
def pendingFeature = Utils.specAnnotation( data, PendingFeature )
if ( pendingFeature ) {
writePendingFeature( builder, pendingFeature )
}
def sees = Utils.specAnnotation( data, See )
if ( sees ) {
writeIssuesOrSees( builder, sees, 'See:' )
}
def headers = Utils.specHeaders( data )
if ( headers ) {
writeHeaders( builder, headers )
}
writeTagOrAttachment( builder, data.info)
builder.h3 "Features:"
builder.table( 'class': 'features-table' ) {
colgroup {
Expand Down Expand Up @@ -246,10 +242,9 @@ class HtmlReportCreator extends AbstractHtmlCreator<SpecData>
Utils.isSkipped( feature ) ? 'ignored' : ''
writeFeatureDescription( builder, name, cssClass,
feature.description.getAnnotation( Ignore ),
feature.description.getAnnotation( Issue ),
feature.description.getAnnotation( See ),
feature.description.getAnnotation( PendingFeature ),
extraInfo )
extraInfo,
run.feature )
writeFeatureBlocks( builder, feature, problems, iteration )
writeRun( builder, run, iteration )
problemWriter.writeProblemBlockForIteration( builder, iteration, problems )
Expand All @@ -268,10 +263,9 @@ class HtmlReportCreator extends AbstractHtmlCreator<SpecData>

writeFeatureDescription( builder, feature.name, cssClass,
feature.description.getAnnotation( Ignore ),
feature.description.getAnnotation( Issue ),
feature.description.getAnnotation( See ),
feature.description.getAnnotation( PendingFeature ),
extraInfo )
extraInfo,
run?.feature )
def problems = run ? run.failuresByIteration.values().collectMany { it } : [ ]
writeFeatureBlocks( builder, feature, problems )
if ( run ) {
Expand Down Expand Up @@ -502,10 +496,9 @@ class HtmlReportCreator extends AbstractHtmlCreator<SpecData>
private void writeFeatureDescription( MarkupBuilder builder, String name,
String cssClass,
Ignore ignoreAnnotation,
Issue issueAnnotation,
See seeAnnotation,
PendingFeature pendingFeature,
List extraInfo ) {
List extraInfo,
SpecElementInfo feature ) {
def ignoreReason = ''
if ( cssClass == 'ignored' && ignoreAnnotation ) {
ignoreReason = ignoreAnnotation.value()
Expand All @@ -522,28 +515,50 @@ class HtmlReportCreator extends AbstractHtmlCreator<SpecData>
div()
span( 'class': 'reason', ignoreReason )
}
writeIssuesOrSees builder, issueAnnotation, 'Issues:'
writePendingFeature( builder, pendingFeature )
writeIssuesOrSees builder, seeAnnotation, 'See:'
writeExtraInfo( builder, extraInfo )
if ( feature ) {
writeTagOrAttachment builder, feature
}
}
}
}
}

private void writeIssuesOrSees( MarkupBuilder builder, Annotation annotation, String description ) {
if ( annotation?.value() ) {
builder.div( 'class': 'issues' ) {
div( description )
private void writeTagOrAttachment( MarkupBuilder builder, SpecElementInfo feature ) {

if ( feature.attachments.isEmpty() && feature.tags.isEmpty()) {
return;
}

builder.div( 'class': 'issues' ) {
if ( !feature.tags.isEmpty() ) {
def tagsByKey = feature.tags.groupBy( { t -> t.key } )
tagsByKey.each { key, values ->
div( key.capitalize() + 's:' )
ul {
for ( Tag value in values ) {
li {
if ( Utils.isUrl( value.url ) ) {
a( 'href': value.url ) { mkp.yield value.name }
} else {
span stringFormatter.escapeXml( value.name )
}
}
}
}
}
}

if (!feature.attachments.isEmpty()) {
div( 'See:' )
ul {
for ( String value in annotation.value() ) {
for ( Attachment value in feature.attachments ) {
li {
if ( Utils.isUrl( value ) ) {
a( 'href': value ) {
mkp.yield value
}
if ( Utils.isUrl( value.url ) ) {
a( 'href': value.url ) { mkp.yield value.name }
} else {
span stringFormatter.escapeXml( value )
span stringFormatter.escapeXml( value.name )
}
}
}
Expand Down
23 changes: 14 additions & 9 deletions src/main/resources/templateReportCreator/spec-template.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,20 @@
out << '<pre>\n' << data.info.narrative << '\n</pre>'
}

def writeIssuesOrSees = { issues, description ->
if ( issues?.value() ) {
out << '\n#### ' << description << ':\n\n'
issues.value().each { issue ->
out << '* ' << issue << '\n'
def writeTagOrAttachment = { feature ->
def tagsByKey = feature.tags.groupBy( { t -> t.key } )
tagsByKey.each { key, values ->
out << '\n#### ' << key.capitalize() << 's:\n\n'
values.each { tag ->
out << '* ' << tag.url << '\n'
}
}
if ( feature.attachments.size > 0 ) {
out << '\n#### ' << 'See:' << '\n\n'
feature.attachments.each { value ->
out << '* ' << value.url << '\n'
}
}
}
def writePendingFeature = { pendingFeature ->
if ( pendingFeature ) {
Expand All @@ -48,9 +55,8 @@
}
}
}
writeIssuesOrSees( utils.specAnnotation( data, spock.lang.Issue ), 'Issues' )
writeIssuesOrSees( utils.specAnnotation( data, spock.lang.See ), 'See' )
writeHeaders( utils.specHeaders( data ) )
writeTagOrAttachment data.info
%>

## Features
Expand All @@ -60,8 +66,7 @@
### $name
<%
writePendingFeature( description.getAnnotation( spock.lang.PendingFeature ) )
writeIssuesOrSees( description.getAnnotation( spock.lang.Issue ), 'Issues' )
writeIssuesOrSees( description.getAnnotation( spock.lang.See ), 'See' )
writeTagOrAttachment( delegate )
if ( utils.isUnrolled( delegate ) ) {
writeExtraInfo( utils.nextSpecExtraInfo( data ) )
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class FakeTest extends Specification {
"Nothing happens"
}

@Issue( [ "http://myhost.com/issues/995", "http://myhost.com/issues/973" ] )
@Issue( [ "http://myhost.com/issues/995", "https://myhost.com/issues/973" ] )
def "A test with an error"() {
when:
"An Exception is thrown"
Expand All @@ -76,7 +76,7 @@ class FakeTest extends Specification {
"Will never succeed"
}

@See( "http://myhost.com/features/feature-234" )
@See( [ "http://myhost.com/features/feature-234" ] )
def "A test with a failure"() {
when:
"Do nothing"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class VividFakeTest extends Specification {
return a + b
}

@Issue( [ "http://myhost.com/issues/995", "http://myhost.com/issues/973" ] )
@Issue( [ "http://myhost.com/issues/995", "https://myhost.com/issues/973" ] )
def "A test with an error"() {
when:
"An Exception is thrown"
Expand All @@ -57,7 +57,7 @@ class VividFakeTest extends Specification {
"Will never succeed"
}

@See( "http://myhost.com/features/feature-234" )
@See( [ "http://myhost.com/features/feature-234" ] )
def "A test with a failure"() {
when:
"Do nothing"
Expand Down
2 changes: 1 addition & 1 deletion src/test/resources/FakeTest.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ Result: **IGNORED**
#### Issues:

* http://myhost.com/issues/995
* http://myhost.com/issues/973
* https://myhost.com/issues/973

Result: **ERROR**

Expand Down
2 changes: 1 addition & 1 deletion src/test/resources/VividFakeTest.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ add( 1, 2 ) == 3
#### Issues:

* http://myhost.com/issues/995
* http://myhost.com/issues/973
* https://myhost.com/issues/973

Result: **ERROR**

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,9 @@ <h3>Features:</h3>
<div class='issues'>
<div>Issues:</div>
<ul>
<li><a href='http://myhost.com/issues/995'>http://myhost.com/issues/995</a></li>
<li><a href='http://myhost.com/issues/973'>http://myhost.com/issues/973</a></li>
</ul>
<li><a href='http://myhost.com/issues/995'>995</a></li>
<li><a href='https://myhost.com/issues/973'>973</a></li>
</ul>
</div>
</div>
</td>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,8 @@ <h3>Features:</h3>
<div class='issues'>
<div>Issues:</div>
<ul>
<li><a href='http://myhost.com/issues/995'>http://myhost.com/issues/995</a></li>
<li><a href='http://myhost.com/issues/973'>http://myhost.com/issues/973</a></li>
<li><a href='http://myhost.com/issues/995'>995</a></li>
<li><a href='https://myhost.com/issues/973'>973</a></li>
</ul>
</div>
</div>
Expand Down

0 comments on commit 0b9b84c

Please sign in to comment.