I was aware that the methods to set up a Specification (test class) and a feature (test method) are, respectively, setupSpec
and setup
...
I wasn't quite sure what the corresponding "tear down" methods are so I thought I'd look it up. Turns out these are cleanupSpec
and cleanup
respectively, as documented here.
But I also looked up the Spock 1.2 API Javadoc. Not only does it turn out that none of the above 4 methods is a method of spock.lang.Specification
, but looking up the index of this Javadoc I find no reference to any of them.
Obviously Spock is Groovy rather than Java, so perhaps this is explained by some Groovy magic going on. Can anyone explain where these methods come from?
Interestingly, I can't actually find the Spock 1.2 API Javadoc online to link to. I compiled mine from the source .jar downloaded by Gradle.
I've tried to find answer in spock source code, and I found out that it's uses GroovyClassVisitor to find and execute this methods.
Quick breakdown of what happening:
Indentifiers.java class that contains constants like method names (line 58) and collection with all "fixture method names" (line 72)
SpecParser.java GroovyClassVisitor that parses all specs, and try to find fixture methods and build FixtureMethods (method buildFixtureMethod at line 131)