Skip to content

Commit

Permalink
#11, new approach: auto detect filter type, check against argsMap i…
Browse files Browse the repository at this point in the history
…nstead of `testTargetPattern`
  • Loading branch information
hauner committed Jun 15, 2012
1 parent 33913d1 commit f1acbdb
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 24 deletions.
5 changes: 3 additions & 2 deletions src/groovy/grails/plugin/cucumber/CucumberTestType.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,16 @@ 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 args = buildBinding.argsMap.params
//def properties = System.getProperties().getProperty("cucumber.options")

def resourceLoader = new FileResourceLoader ()
def classLoader = getTestClassLoader ()
def groovyShell = new GroovyShell (classLoader, createBinding ())
def groovyBackend = new GroovyBackend (groovyShell, resourceLoader)

def summaryPrinter = new SummaryPrinter (System.out)
def runtimeOptions = new RuntimeOptionsBuilder (configObject).build ()
def runtimeOptions = new RuntimeOptionsBuilder (configObject).build (args)
def runtime = new Runtime (resourceLoader, classLoader, [groovyBackend], runtimeOptions)

cucumber = new Cucumber (resourceLoader, runtime, runtimeOptions, summaryPrinter)
Expand Down
24 changes: 22 additions & 2 deletions src/groovy/grails/plugin/cucumber/RuntimeOptionsBuilder.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,39 @@ class RuntimeOptionsBuilder {
this.configObject = configObject
}

RuntimeOptions build () {
RuntimeOptions build (List<String> args) {
def options = new RuntimeOptions (new Properties ())

setTags (options)
setFormatter (options)
setGluePaths (options)
setFeaturePaths (options)

addCliFilter (options)
addCliFilter (options, args)
//addCliFilter (options) //-Dcucumber.options='--tags @ignore --name .*bla.* file/feature:8:9'

options
}

def addCliFilter (RuntimeOptions options, List<String> args) {
if (args.size() < 2 || ! args.first().contains(":cucumber")) {
return
}

options.filters.clear ()

args.each { arg ->
switch (arg) {
case ~/\w*:cucumber/:
break;
case ~/~?@.+(:\d)?/:
options.filters << arg
break;
}
}
}

// obsolete
def addCliFilter (RuntimeOptions options) {
def args = configObject.cucumber.cliOptions
if (!args)
Expand Down
68 changes: 48 additions & 20 deletions test/unit/grails/plugin/cucumber/RuntimeOptionsBuilderSpec.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ class RuntimeOptionsBuilderSpec extends Specification {


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

RuntimeOptions createRuntimeOptions (ConfigObject configObject, List<String> args) {
new RuntimeOptionsBuilder (configObject).build (args)
}

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

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 = [
Expand All @@ -142,8 +131,9 @@ class RuntimeOptionsBuilderSpec extends Specification {
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 = [
Expand All @@ -160,21 +150,59 @@ class RuntimeOptionsBuilderSpec extends Specification {
options.filters.size () == 2
options.filters.contains([1L])
options.filters.contains([1L, 2L])
}*/

def "evaluate cli if first arg contains ':cucumber'" () {
given:
def args = [':cucumber', '@tag']

when:
def options = createRuntimeOptions (configObject, args)

then:
! options.filters.contains (args[0])
options.filters.contains (args[1])
}

def "ignore cli if first arg is not ':cucumber'" () {
given:
def args = ['functional:', '@tag']

when:
def options = createRuntimeOptions (configObject, args)

then:
! options.filters.contains (args[0])
! options.filters.contains (args[1])
}

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

when:
def options = createRuntimeOptions (configObject)
def options = createRuntimeOptions (configObject, args)

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

def "adds auto detected tag filter from cli" () {
given:
def args = [':cucumber', '@tag1', '~@tag2', '@tagA,@tagB', '@tag:9']

when:
def options = createRuntimeOptions (configObject, args)

then:
options.filters.contains (args[1])
options.filters.contains (args[2])
options.filters.contains (args[3])
options.filters.contains (args[4])
}

/*
def "gives warning when multiple filter types are given on cli" () {
given:
Expand Down

0 comments on commit f1acbdb

Please # to comment.