Spock extension for shell script.
Apache License, Version 2.0
apply plugin: 'groovy'
repositories {
mavenCentral()
maven { url 'http://repo.kiy0taka.org/' }
}
dependencies {
groovy 'org.codehaus.groovy:groovy-all:2.0.6'
testCompile 'org.kiy0taka.spock:spock-shell:0.4'
}
src/test/groovy/ShellSpec.groovy
key | required | default | description |
---|---|---|---|
script.dir | yes | - | path to shell script directory. |
report.dir | no | build/reports/spock-shell | path to report directory. |
See https://github.com/kiy0taka/spock-shell/blob/master/src/test/groovy/ShellSpecConfig.groovy
See ShellSpecSpec
run 'myscript.sh', 'arg0', 'arg1'
exec 'echo "Hello!"'
export 'VAR', 'VALUE'
name | type | description |
---|---|---|
status | int | Exit status |
stdout | String | Standard Output |
stderr | String | Standard Error |
lines | List<String> | Standard Output lines |
workspace | File | Shell working directory |
-
mock.sh
function curl { echo "called curl $*" }
-
run.sh
curl http://www.google.com
-
RunSpec.groovy
setup: mockScript 'mock.sh' when: run 'run.sh' then: lines[0] == 'called curl http://www.google.com'
given:
mockFunction('curl') { args ->
new File(workspace, 'index.html').text = 'Hello World'
}
when:
exec 'curl -O index.html http://www.example.org'
then:
def downloaded = new File(workspace, 'index.html')
downloaded.exists()
downloaded.text == 'Hello World'
Copy src/resources/test direcotry to workspace.
resources 'test'