Evaluate @IgnoreIf condition for @Shared value #628

Open
yeugenius opened this Issue Aug 2, 2016 · 0 comments

Projects

None yet

1 participant

@yeugenius

Issue description

Spock supports conditional skipping using @IgnoreIf and @Requires annotations, but this functionality is very limited, as predicates are evaluated before Spec is loaded and started.

If would be very useful to add possibility to use flexible ignore tests functionality based on data from setupSpec() and setup() methods.

So the Spec can decide which tests to skip based on input data. Test only what is testable and skip everything else.

It is useful for testing documents structure and data flow when fields, block and attributes are not mandatory and documents in data flow could have them in numerous combinations.

How to reproduce:

@Shared condition = true

//OR

@Shared condition
def setupSpec(){
        condition=true
}


@IgnoreIf({condition})
def test01(){
expect:
1==1
}
Internal Error occured.
org.spockframework.runtime.extension.ExtensionException: Failed to evaluate @IgnoreIf condition
    at org.spockframework.runtime.extension.builtin.IgnoreIfExtension.evaluateCondition(IgnoreIfExtension.java:63)
    at org.spockframework.runtime.extension.builtin.IgnoreIfExtension.doVisit(IgnoreIfExtension.java:44)
    at org.spockframework.runtime.extension.builtin.IgnoreIfExtension.visitFeatureAnnotation(IgnoreIfExtension.java:39)
    at org.spockframework.runtime.extension.builtin.IgnoreIfExtension.visitFeatureAnnotation(IgnoreIfExtension.java:31)
    at org.spockframework.runtime.ExtensionRunner.doRunAnnotationDrivenExtensions(ExtensionRunner.java:95)
    at org.spockframework.runtime.ExtensionRunner.runAnnotationDrivenExtensions(ExtensionRunner.java:74)
    at org.spockframework.runtime.ExtensionRunner.runAnnotationDrivenExtensions(ExtensionRunner.java:51)
    at org.spockframework.runtime.ExtensionRunner.run(ExtensionRunner.java:41)
    at org.spockframework.runtime.Sputnik.runExtensionsIfNecessary(Sputnik.java:88)
    at org.spockframework.runtime.Sputnik.getDescription(Sputnik.java:55) 
    ...
Caused by: groovy.lang.MissingPropertyException: No such property: condition for class: org.spockframework.runtime.extension.builtin.PreconditionContext
    at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:53)
    at org.codehaus.groovy.runtime.callsite.PogoGetPropertySite.getProperty(PogoGetPropertySite.java:52)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGroovyObjectGetProperty(AbstractCallSite.java:307)
    ...
@yeugenius yeugenius changed the title from Evaluate @IgnoreIf condition for @Shared condition to Evaluate @IgnoreIf condition for @Shared value Aug 2, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment