Skip to content

Commit

Permalink
BuildScript allows calling addJob method.
Browse files Browse the repository at this point in the history
  • Loading branch information
Miro Bezjak committed Aug 6, 2011
1 parent b5d2d5c commit 7720aea
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/main/groovy/hr/helix/kin/script/BuildScript.groovy
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -16,12 +16,17 @@ abstract class BuildScript extends Script {


def methodMissing(String name, args) { def methodMissing(String name, args) {
if (args.size() == 1 && args[0] instanceof Closure) { if (args.size() == 1 && args[0] instanceof Closure) {
def job = new Job(name) addJob name, args[0]
job.with args[0]
_build.add job
} else { } else {
throw new MissingMethodException(name, delegate, args) throw new MissingMethodException(name, delegate, args)
} }
} }


Job addJob(String name, Closure configurer) {
def job = new Job(name)
job.with configurer
_build.add job
job
}

} }
18 changes: 18 additions & 0 deletions src/test/groovy/hr/helix/kin/script/RunnerSpec.groovy
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -67,4 +67,22 @@ class RunnerSpec extends Specification {
jobs.quux.deploy == true jobs.quux.deploy == true
} }


def "run should allow calling addJob method"() {
when:
def build = runner.run("""
addJob 'foo', {
a = 1
b = 2
}
""")

then:
def jobs = build.jobs
jobs.size() == 1

and:
jobs.foo.a == 1
jobs.foo.b == 2
}

} }

0 comments on commit 7720aea

Please sign in to comment.