Last active
August 15, 2018 22:46
-
-
Save imayobrown/daa0fab50a1a971b451b7f2435462ccc to your computer and use it in GitHub Desktop.
Testing format example (no subfunctions)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!groovy | |
package tests | |
import support.PipelineSpockTestBase | |
class TestThing extends PipelineSpockTestBase { | |
def scriptPath = 'vars/thing.groovy' | |
def script = null | |
def setup() { | |
this.script = loadScript(scriptPath) | |
} | |
def 'test thing'() { | |
given: | |
Closure mockWithStuff = Mock() | |
Closure mockLeaveWithStuff = Mock() | |
Closure mockDoTheThing = Mock() | |
helper.registerAllowedMethod('doTheThing', [Map.class], mockDoTheThing) | |
helper.registerAllowedMethod('withStuff', [Map.class], { args -> | |
mockWithStuff(args) | |
args.block() | |
mockLeaveWithStuff() | |
}) | |
when: | |
script() | |
then: | |
1 * mockWithStuff({ mapArgs -> | |
mapArgs.arg1 == "arg" | |
}) | |
then: | |
1 * mockDoTheThing({ mapArgs -> | |
mapArgs.foo == "foo" && | |
mapArgs.bar == "bar" | |
}) | |
then: | |
1 * mockLeaveWithStuff() | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!groovy | |
def call(Map args) { | |
withStuff arg1: "arg", block: { | |
doTheThing foo: "foo", bar: "bar" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment