Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Trying to compose spock specs with mixins
import grails.plugin.spock.UnitSpec;
import org.codehaus.groovy.runtime.ArrayUtil;
import org.codehaus.groovy.runtime.callsite.CallSite;
import org.spockframework.runtime.model.FeatureMetadata;
import org.spockframework.runtime.model.FieldMetadata;
import org.spockframework.runtime.model.SpecMetadata;
@SpecMetadata(filename="PrincipalSpec.groovy")
public class PrincipalSpec extends UnitSpec
{
@FieldMetadata(name="principalField", ordinal=0, line=14)
private Object principalField;
public PrincipalSpec()
{
CallSite[] arrayOfCallSite = $getCallSiteArray();
}
public void My principal test()
{
CallSite[] arrayOfCallSite = $getCallSiteArray();
arrayOfCallSite[0].call($get$$class$org$spockframework$runtime$SpockRuntime());
return;
}
@FeatureMetadata(name="My principal test", ordinal=0, parameterNames={}, blocks={@org.spockframework.runtime.model.BlockMetadata(kind=org.spockframework.runtime.model.BlockKind.SETUP, texts={}), @org.spockframework.runtime.model.BlockMetadata(kind=org.spockframework.runtime.model.BlockKind.EXPECT, texts={})})
public void $spock_feature_1_0()
{
CallSite[] arrayOfCallSite = $getCallSiteArray(); Object $spock_valueRecorder = arrayOfCallSite[1].callConstructor($get$$class$org$spockframework$runtime$ValueRecorder()); arrayOfCallSite[2].callCurrent(this, "I am the only one");
arrayOfCallSite[3].callCurrent(this, arrayOfCallSite[4].callCurrent(this));
arrayOfCallSite[5].call($get$$class$org$spockframework$runtime$SpockRuntime(), ArrayUtil.createArray(arrayOfCallSite[6].call($spock_valueRecorder), "true", Integer.valueOf(18), Integer.valueOf(11), null, arrayOfCallSite[7].call($spock_valueRecorder, $const$1, Boolean.TRUE))); arrayOfCallSite[8].call(arrayOfCallSite[9].callGroovyObjectGetProperty(this)); return;
}
public Object getPrincipalField()
{
return this.principalField;
}
public void setPrincipalField(Object paramObject)
{
this.principalField = paramObject;
}
}
import grails.plugin.spock.UnitSpec;
@Mixin(ToMixWithPrincipalSpec)
class PrincipalSpec extends UnitSpec {
def principalField="principalField"
def "My principal test"() {
given: println "I am the only one"
and: println secondaryMethod()
expect: true
}
}
/*
grails testApp unit: PrincipalSpec
....
Tests passed: 1
Tests failed: 0
--Output from My principal test--
I am the only one
Hi from helper method of ToMix:principalField
I guess the spock ast trans dont see the feature method of mixed spec (see reverse PrincipalSpec.class)
or i am missing something basic thing
Too much magic at same time ;-)
It seems a spock extension would be neccesary to make it possible/user friendly
*/
import grails.plugin.spock.UnitSpec;
class ToMixWithPrincipalSpec extends UnitSpec{
def "My mixed test" () {
given: println "hey, i am too"
expect: true
}
def secondaryMethod() {
"Hi from helper method of ToMix:"+principalField
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment