Skip to content

Commit

Permalink
#11 handle commandline arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
hauner committed Jun 10, 2012
1 parent b88b0a3 commit 678d355
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/groovy/grails/plugin/cucumber/CucumberTestType.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class CucumberTestType extends GrailsTestTypeSupport {
def configObject = configReader.parse ()
configObject.cucumber.defaultFeaturePath = featurePath ()
configObject.cucumber.defaultGluePath = featurePath ()
configObject.cucumber.cliOptions = testTargetPatterns.collect {it -> it.rawPattern}

def resourceLoader = new FileResourceLoader ()
def classLoader = getTestClassLoader ()
Expand Down
29 changes: 28 additions & 1 deletion src/groovy/grails/plugin/cucumber/RuntimeOptionsBuilder.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package grails.plugin.cucumber

import cucumber.runtime.RuntimeOptions
import cucumber.runtime.PathWithLines


class RuntimeOptionsBuilder {
Expand All @@ -34,9 +35,36 @@ class RuntimeOptionsBuilder {
setGluePaths (options)
setFeaturePaths (options)

addCliFilter (options)

options
}

def addCliFilter (RuntimeOptions options) {
def args = configObject.cucumber.cliOptions
if (!args)
return

options.filters.clear ()

while (!args.empty) {
String arg = args.remove (0)

switch (arg) {
case ['++tags', '+t']:
options.filters << args.remove (0)
break
case ['++name', '+n']:
options.filters << ~args.remove (0)
break
default:
PathWithLines pathWithLines = new PathWithLines (arg.replace ('|', ':'))
options.featurePaths << pathWithLines.path
options.filters << pathWithLines.lines
}
}
}

private void setGluePaths (RuntimeOptions options) {
def glue = configObject.cucumber.glue
if (glue) {
Expand Down Expand Up @@ -67,5 +95,4 @@ class RuntimeOptionsBuilder {
}
}


}
80 changes: 77 additions & 3 deletions test/unit/grails/plugin/cucumber/RuntimeOptionsBuilderSpec.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package grails.plugin.cucumber

import cucumber.runtime.RuntimeOptions
import spock.lang.Specification
import java.util.regex.Pattern


class RuntimeOptionsBuilderSpec extends Specification {
Expand All @@ -27,7 +28,9 @@ class RuntimeOptionsBuilderSpec extends Specification {
def CUSTOM_PATHS = ["path_a", "path_b"]
def configObject = new ConfigObject ()

def setup () {

RuntimeOptions createRuntimeOptions (ConfigObject configObject) {
new RuntimeOptionsBuilder (configObject).build ()
}

def "adds tags from configuration to options" () {
Expand Down Expand Up @@ -109,7 +112,78 @@ class RuntimeOptionsBuilderSpec extends Specification {
options.formatters.empty
}

RuntimeOptions createRuntimeOptions (ConfigObject configObject) {
new RuntimeOptionsBuilder (configObject).build ()
def "adds '++tags|+t tag' filter from cli" () {
given:
configObject.cucumber.cliOptions = [
'+t', '@short',
'++tags', '@full',
]

when:
def options = createRuntimeOptions (configObject)

then:
options.filters.size () == 2
options.filters.find { it == "@short" }
options.filters.find { it == "@full" }
}

def "adds '++name|+n scenario regex' filter from cli" () {
given:
configObject.cucumber.cliOptions = [
'+n', '@short',
'++name', '@full',
]

when:
def options = createRuntimeOptions (configObject)

then:
options.filters.size () == 2
options.filters.find { Pattern p -> p.pattern () == "@short" }
options.filters.find { Pattern p -> p.pattern () == "@full" }
}

def "adds '[[FILE|DIR|URL][|LINE[|LINE]*]]+' filter from cli" () {
given:
configObject.cucumber.cliOptions = [
'my/feature/a|1',
'my/feature/b|1|2'
]

when:
def options = createRuntimeOptions (configObject)

then:
options.featurePaths.contains('my/feature/a')
options.featurePaths.contains('my/feature/b')
options.filters.size () == 2
options.filters.contains([1L])
options.filters.contains([1L, 2L])
}

def "cli filter override config filter" () {
given:
configObject.cucumber.tags = TAGS
configObject.cucumber.cliOptions = ['anything']

when:
def options = createRuntimeOptions (configObject)

then:
options.filters.indexOf (TAGS[0]) < 0
options.filters.indexOf (TAGS[1]) < 0
}

/*
def "gives warning when multiple filter types are given on cli" () {
given:
configObject.cucumber.cliOptions = [
'+n', '@short',
'++name', '@full',
'my/feature/a:1'
]
}
*/
}

0 comments on commit 678d355

Please sign in to comment.