-
Notifications
You must be signed in to change notification settings - Fork 468
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This feature allows extension authors to register a IBlockListener for a feature to observe the execution of a feature in more detail. This surfaces some of Spock's idiosyncrasies, for example interaction assertions are actually setup right before entering the preceding `when`-block as well as being evaluated on leaving the `when`-block before actually entering the `then`-block. The only valid block description is a constant String, although some users mistakenly try to use a dynamic GString. Using anything other than a String, will be treated as a separate statement and thus ignored.
- Loading branch information
Showing
9 changed files
with
148 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
spock-core/src/main/java/org/spockframework/runtime/extension/IBlockListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package org.spockframework.runtime.extension; | ||
|
||
import org.spockframework.runtime.model.BlockInfo; | ||
import org.spockframework.runtime.model.IterationInfo; | ||
|
||
public interface IBlockListener { | ||
void blockEntered(IterationInfo iterationInfo, BlockInfo blockInfo); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
spock-specs/src/test/groovy/org/spockframework/runtime/BlockListenerSpec.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package org.spockframework.runtime | ||
|
||
import org.spockframework.runtime.model.BlockInfo | ||
import org.spockframework.runtime.model.BlockKind | ||
import org.spockframework.runtime.model.IterationInfo | ||
import spock.lang.Specification | ||
|
||
class BlockListenerSpec extends Specification { | ||
|
||
List<BlockInfo> blocks = [] | ||
|
||
def setup() { | ||
specificationContext.currentIteration.feature.addBlockListener { IterationInfo i, BlockInfo b -> | ||
blocks << b | ||
} | ||
} | ||
|
||
def "BlockListener is called for each Block with text"() { | ||
given: "setup" | ||
expect: "precondition" | ||
when: "action" | ||
then: "assertion" | ||
|
||
cleanup: "cleanup" | ||
assert blocks.kind == [BlockKind.SETUP, BlockKind.EXPECT, BlockKind.WHEN, BlockKind.THEN, BlockKind.CLEANUP] | ||
assert blocks.texts == [["setup"], ["precondition"], ["action"], ["assertion"], ["cleanup"]] | ||
} | ||
|
||
def "SpecificationContext holds a reference to the current block"() { | ||
assert specificationContext.currentBlock == null | ||
given: "setup" | ||
assert specificationContext.currentBlock.kind == BlockKind.SETUP | ||
expect: "precondition" | ||
specificationContext.currentBlock.kind == BlockKind.EXPECT | ||
when: "action" | ||
assert specificationContext.currentBlock.kind == BlockKind.WHEN | ||
then: "assertion" | ||
specificationContext.currentBlock.kind == BlockKind.THEN | ||
|
||
cleanup: "cleanup" | ||
assert specificationContext.currentBlock.kind == BlockKind.CLEANUP | ||
} | ||
|
||
def "blocks extended with and: are treated as singular block with multiple texts"() { | ||
given: "setup" | ||
and: "setup2" | ||
expect: "precondition" | ||
and: "precondition2" | ||
when: "action" | ||
and: "action2" | ||
then: "assertion" | ||
and: "assertion2" | ||
|
||
cleanup: "cleanup" | ||
assert blocks.kind == [BlockKind.SETUP, BlockKind.EXPECT, BlockKind.WHEN, BlockKind.THEN, BlockKind.CLEANUP] | ||
and: "cleanup2" | ||
assert blocks.texts == [["setup", "setup2"], ["precondition", "precondition2"], ["action", "action2"], ["assertion", "assertion2"], ["cleanup", "cleanup2"]] | ||
} | ||
} |