From 1089e192f33e6097ad626f167a47804f4178e0ba Mon Sep 17 00:00:00 2001 From: Thorsten Duda Date: Tue, 16 Jan 2018 14:39:42 +0100 Subject: [PATCH] added JenkinsShellCallRule class --- test/groovy/util/JenkinsShellCallRule.groovy | 38 ++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 test/groovy/util/JenkinsShellCallRule.groovy diff --git a/test/groovy/util/JenkinsShellCallRule.groovy b/test/groovy/util/JenkinsShellCallRule.groovy new file mode 100644 index 000000000..128fd4577 --- /dev/null +++ b/test/groovy/util/JenkinsShellCallRule.groovy @@ -0,0 +1,38 @@ +package util + +import com.lesfurets.jenkins.unit.BasePipelineTest +import org.junit.rules.TestRule +import org.junit.runner.Description +import org.junit.runners.model.Statement + +class JenkinsShellCallRule implements TestRule { + + final BasePipelineTest testInstance + + String shell = "" + + JenkinsShellCallRule(BasePipelineTest testInstance) { + this.testInstance = testInstance + } + + @Override + Statement apply(Statement base, Description description) { + return statement(base) + } + + private Statement statement(final Statement base) { + return new Statement() { + @Override + void evaluate() throws Throwable { + + testInstance.helper.registerAllowedMethod("sh", [String.class], { + command -> + command = command.replaceAll(/\s+/," ").trim() + shell += "$command \n" + }) + + base.evaluate() + } + } + } +}