Reputation: 1193
When I try to test for a thrown exception using the following code:
@TestFor(EncryptionService)
class EncryptionServiceSpec extends Specification {
def "test decryption of unecnrypted file"(){
setup:
def clearTextFile = new File("test/resources/clearText.txt")
clearTextFile.write("THIS IS CLEAR TEXT")
when:
def (privateKey,publicCert) = service.generateKeyPair("123")
service.decryptFile(new FileInputStream(clearTextFile), privateKey )
then:
clearTextFile.delete()
thrown GeneralSecurityException
}
}
I get the following compilation exception when I run either grails test-app -unit
Unexpected error during compilation of spec 'com.genospace.services.EncryptionServiceSpec'. Maybe you have used invalid Spock syntax? Anyway, please file a bug report at http://issues.spockframework.org.
java.lang.ClassCastException: org.codehaus.groovy.ast.expr.ArgumentListExpression cannot be cast to org.codehaus.groovy.ast.expr.VariableExpression at org.codehaus.groovy.ast.expr.DeclarationExpression.getVariableExpression(DeclarationExpression.java:103) at org.spockframework.compiler.SpecRewriter.moveVariableDeclarations(SpecRewriter.java:538)
Upvotes: 0
Views: 1946
Reputation: 123910
Try without leveraging Groovy's multi-assignment feature (def (privateKey,publicCert) = ...
). If this solves the problem (and I think it will), please file an issue at http://issues.spockframework.org.
Upvotes: 1