how to mock properties provided by the SeedJob in a TestSpec

71 views
Skip to first unread message

Torsten Reinhard

unread,
May 19, 2015, 5:12:43 AM5/19/15
to job-dsl...@googlegroups.com


Hi,

I want to use the given example com.dslexample.JobScriptsSpec to ensure all of my *.groovy code is compiling.

When running

> gradlew test --info

I got the following error:

com.dslexample.JobScriptsSpec > test script Validate-WLS-Config.groovy FAILED
   
Expected no exception to be thrown, but got 'groovy.lang.MissingPropertyException'
        at spock
.lang.Specification.noExceptionThrown(Specification.java:118)
        at com
.dslexample.JobScriptsSpec.test script #file.name(JobScriptsSpec.groovy:24)

       
Caused by:
        groovy
.lang.MissingPropertyException: No such property: ENVIRONMENT for class: script14320244323261021416627
            at script14320244323261021416627
.run(script14320244323261021416627.groovy:6)
            at javaposse
.jobdsl.dsl.DslScriptLoader.runDslEngineForParent(DslScriptLoader.java:72)
            at javaposse
.jobdsl.dsl.DslScriptLoader.runDslEngine(DslScriptLoader.java:92)
            at javaposse
.jobdsl.dsl.DslScriptLoader.runDslEngine(DslScriptLoader.java:88)
            at com
.dslexample.JobScriptsSpec.test script #file.name(JobScriptsSpec.groovy:21)


This is due to my script, that is accessing the environment variables provided in the SeedJob:

// Validate-WLS-Config.groovy
//
String env="${ENVIRONMENT}"
....



how can I mock this ?

So I´m quite new to gradle and the spock-framework, any help appreciated !

Thanx in advance,

Torsten

Daniel Spilker

unread,
May 19, 2015, 5:27:53 AM5/19/15
to job-dsl...@googlegroups.com
Have a look at https://github.com/daspilker/job-dsl-gradle-example/blob/master/src/test/groovy/com/dslexample/JobScriptsSpec.groovy#L19 where getParameters returns an empty map. That's the map of variables available in the script which is populated with the environment variables by the plugin.

You can change that to mock variables:

jm.getParameters() >> [
        FOO: 'bar',
        LOREM: 'ipsum',
]

Daniel

--
You received this message because you are subscribed to the Google Groups "job-dsl-plugin" group.
To unsubscribe from this group and stop receiving emails from it, send an email to job-dsl-plugi...@googlegroups.com.
To post to this group, send email to job-dsl...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/job-dsl-plugin/84ab0335-c563-4af1-a5e3-24645173d007%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages