According to the following article:
https://dzone.com/articles/spocklight-ignore
you should be able to evaluate the Spock @IgnoreIf annotation using a static method. I tried the isOsWindows() method exactly as in the article, and got the following:
org.spockframework.runtime.extension.ExtensionException: Failed to evaluate @IgnoreIf condition
...
Caused by: groovy.lang.MissingMethodException: No signature of method: MySpec$__spock_feature_1_3_closure1.isOsWindows() is applicable for argument types: () values: []
Does anyone have any insight on this? I really want to just set a true/false per spec, I don't need any of the os/system properties listed in the other examples.
Thank you
The example is a little outdated Code written with Spock 0.7-groovy-2, if you want to use a static method then you need use the qualified version ClassName.method().
package com.mrhaki.spock
import spock.lang.*
class SampleRequiresSpec extends Specification {
private static boolean isOsWindows() {
System.properties['os.name'] == 'windows'
}
@IgnoreIf({ SampleRequiresSpec.isOsWindows() })
def "run only if run on non-windows operating system"() {
expect:
true
}
}
If you only want to run on windows, then there are some convenience functions built in (Spock 1.+).
@IgnoreIf({ os.windows || os.linux || os.macOs || os.solaris || os.other }) @IgnoreIf({ jvm.java5 || jvm.java6 || jvm.java7 || jvm.java8 || jvm.java9 })@IgnoreIf({ !env.containsKey("FOOBARBAZ") }) @IgnoreIf({ env["FOOBARBAZ"] == 'false'})@IgnoreIf({ !sys.contains("java.version") }) @IgnoreIf({ sys["java.version"] == '1.6' })If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With