Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
Gleethos committed Apr 28, 2023
2 parents e9905fe + 3449c97 commit 0b1f60d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 12 deletions.
32 changes: 23 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,34 @@ served dynamically.
## Getting Started

To create living react documentation from your Spock test suite,
you need 2 simple dependencies:
you need a few simple dependencies:

The [Spock test framework](https://github.com/spockframework/spock):
First and foremost, the [Spock test framework](https://github.com/spockframework/spock):
```groovy
testImplementation platform("org.spockframework:spock-bom:$spockVersion")
testImplementation "org.spockframework:spock-core"
testImplementation platform("org.spockframework:spock-bom:$spockVersion")
testImplementation "org.spockframework:spock-core"
```
The [Spock reports plugin](https://github.com/renatoathaydes/spock-reports):
Keep in mind that Spock is based on Groovy, so make sure you have
the Groovy plugin for Gradle, otherwise Gradle will not be able
to find (and execute) your Spock tests:
```groovy
// you can use testRuntimeClasspath if you don't want to use spock-report-specific features in your Specs
testImplementation( "com.athaydes:spock-reports:$spockReportsVersion" ) {
transitive = false // this avoids affecting your version of Groovy/Spock
}
plugins {
id 'groovy'
// ... some other plugins ...
}
```
And finally you need the [Spock reports plugin](https://github.com/renatoathaydes/spock-reports)
which is used to generate the raw json files from your Spock tests:
```groovy
// you can use testRuntimeClasspath if you don't want to use spock-report-specific features in your Specs
testImplementation( "com.athaydes:spock-reports:$spockReportsVersion" ) {
transitive = false // this avoids affecting your version of Groovy/Spock
}
// if you don't already have slf4j-api and an implementation of it in the classpath, add this! (needed for reports)
testImplementation 'org.slf4j:slf4j-api:1.7.30'
testImplementation 'org.slf4j:slf4j-simple:1.7.30' // You might need to adjust the version for spock-reports...
```


After you have added the dependencies to your project, you need to
give the report plugin some configuration and templates to work with.
Expand Down
12 changes: 9 additions & 3 deletions spock-conf/templates/spec-template.json
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def strCode = { it == null || it.isEmpty() ? "" : (it.size() == 1 ? ('"'+simpleE


println("Generating json for '"+utils.getSpecClassName( data )+"' now!")

try {
def stats = utils.stats( data )
def subjects = utils.specAnnotation( data, spock.lang.Subject )?.value()
if ( subjects == null ) subjects = []
Expand Down Expand Up @@ -166,7 +166,7 @@ def specTitle = utils.specAnnotation( data, spock.lang.Title )?.value()
}
out << '},'
out << '"see":['
if ( feature.attachments.size > 0 ) out << feature.attachments.collect({v->esc(v.url)}).collect({'"'+it+'"'}).join(",")
if ( feature.attachments.size() > 0 ) out << feature.attachments.collect({v->esc(v.url)}).collect({'"'+it+'"'}).join(",")
out << '],'
}
def writeHeaders = { headers ->
Expand Down Expand Up @@ -256,4 +256,10 @@ def specTitle = utils.specAnnotation( data, spock.lang.Title )?.value()
%>
],
"generator":"<%out << com.athaydes.spockframework.report.SpockReportExtension.PROJECT_URL%>"
}
}
<%
} catch (Exception e) {
e.printStackTrace()
println("ERROR: Failed to generate json for '"+utils.getSpecClassName( data )+"'! Exception: "+e)
}
%>

0 comments on commit 0b1f60d

Please sign in to comment.