Skip to content

Commit 80fbe29

Browse files
Copilotgaeljw
andcommitted
Replace annotation with case class, simplify to single example test
Co-authored-by: gaeljw <[email protected]>
1 parent 0561131 commit 80fbe29

39 files changed

+65
-2025
lines changed

build.sbt

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ lazy val root = (project in file("."))
9292
integrationTestsJackson2.projectRefs ++
9393
integrationTestsJackson3.projectRefs ++
9494
integrationTestsPicoContainer.projectRefs ++
95-
integrationTestsScalatest.projectRefs ++
9695
examplesJunit4.projectRefs ++
9796
examplesJunit5.projectRefs ++
9897
examplesScalatest.projectRefs: _*
@@ -231,22 +230,6 @@ lazy val integrationTestsPicoContainer =
231230
.dependsOn(cucumberScala % Test)
232231
.jvmPlatform(scalaVersions = Seq(scala3, scala213, scala212))
233232

234-
lazy val integrationTestsScalatest =
235-
(projectMatrix in file("integration-tests/scalatest"))
236-
.settings(commonSettings)
237-
.settings(scalatestSbtSupport)
238-
.settings(
239-
name := "integration-tests-scalatest",
240-
libraryDependencies ++= Seq(
241-
"org.scalatest" %% "scalatest" % scalatestVersion % Test,
242-
"org.junit.jupiter" % "junit-jupiter" % junitBom.key.value % Test
243-
),
244-
publishArtifact := false
245-
)
246-
.dependsOn(cucumberScala % Test)
247-
.dependsOn(cucumberScalatest % Test)
248-
.jvmPlatform(scalaVersions = Seq(scala3, scala213, scala212))
249-
250233
// Examples project
251234
lazy val examplesJunit4 = (projectMatrix in file("examples/examples-junit4"))
252235
.settings(commonSettings)

cucumber-scalatest/src/main/java/io/cucumber/scalatest/CucumberOptions.java

Lines changed: 0 additions & 76 deletions
This file was deleted.
Lines changed: 58 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,52 @@
11
package io.cucumber.scalatest
22

3-
import io.cucumber.core.options.{
4-
RuntimeOptionsBuilder,
5-
CucumberOptionsAnnotationParser
6-
}
3+
import io.cucumber.core.options.RuntimeOptionsBuilder
74
import io.cucumber.core.runtime.{Runtime => CucumberRuntime}
85
import org.scalatest.{Args, Status, Suite}
96

107
import scala.annotation.nowarn
118

9+
/** Configuration for Cucumber tests.
10+
*
11+
* @param features
12+
* paths to feature files or directories (e.g., "classpath:features")
13+
* @param glue
14+
* packages containing step definitions (e.g., "com.example.steps")
15+
* @param plugin
16+
* plugins to use (e.g., "pretty", "json:target/cucumber.json")
17+
*/
18+
case class CucumberOptions(
19+
features: List[String] = List.empty,
20+
glue: List[String] = List.empty,
21+
plugin: List[String] = List.empty
22+
)
23+
1224
/** A trait that allows Cucumber scenarios to be run with ScalaTest.
1325
*
14-
* Mix this trait into your test class and optionally annotate it with
15-
* `@CucumberOptions` to configure the Cucumber runtime.
26+
* Mix this trait into your test class and define the `cucumberOptions` value
27+
* to configure the Cucumber runtime.
1628
*
1729
* Example:
1830
* {{{
19-
* import io.cucumber.scalatest.CucumberSuite
20-
* import io.cucumber.core.options.CucumberOptions
31+
* import io.cucumber.scalatest.{CucumberOptions, CucumberSuite}
2132
*
22-
* @CucumberOptions(
23-
* features = Array("classpath:features"),
24-
* glue = Array("com.example.stepdefinitions"),
25-
* plugin = Array("pretty")
26-
* )
27-
* class RunCucumberTest extends CucumberSuite
33+
* class RunCucumberTest extends CucumberSuite {
34+
* override val cucumberOptions = CucumberOptions(
35+
* features = List("classpath:features"),
36+
* glue = List("com.example.stepdefinitions"),
37+
* plugin = List("pretty")
38+
* )
39+
* }
2840
* }}}
2941
*/
3042
@nowarn
3143
trait CucumberSuite extends Suite {
3244

45+
/** Override this value to configure Cucumber options. If not overridden,
46+
* defaults will be used based on the package name.
47+
*/
48+
def cucumberOptions: CucumberOptions = CucumberOptions()
49+
3350
/** Runs the Cucumber scenarios.
3451
*
3552
* @param testName
@@ -75,35 +92,34 @@ trait CucumberSuite extends Suite {
7592
}
7693

7794
private def buildRuntimeOptions(): io.cucumber.core.options.RuntimeOptions = {
78-
// Try the built-in annotation parser which works with various annotations
79-
val annotationParser = new CucumberOptionsAnnotationParser()
8095
val packageName = getClass.getPackage.getName
81-
val featurePath = "classpath:" + packageName.replace('.', '/')
82-
83-
try {
84-
val annotationOptions = annotationParser.parse(getClass).build()
85-
val options = new RuntimeOptionsBuilder().build(annotationOptions)
86-
87-
// If no features were specified, use convention (classpath:package/name)
88-
if (options.getFeaturePaths().isEmpty) {
89-
val builder = new RuntimeOptionsBuilder()
90-
builder.addFeature(
91-
io.cucumber.core.feature.FeatureWithLines.parse(featurePath)
92-
)
93-
builder.addGlue(java.net.URI.create("classpath:" + packageName))
94-
builder.build(annotationOptions)
95-
} else {
96-
options
97-
}
98-
} catch {
99-
case _: Exception =>
100-
// If that fails, use convention based on package name
101-
val builder = new RuntimeOptionsBuilder()
102-
builder.addFeature(
103-
io.cucumber.core.feature.FeatureWithLines.parse(featurePath)
104-
)
105-
builder.addGlue(java.net.URI.create("classpath:" + packageName))
106-
builder.build()
96+
val builder = new RuntimeOptionsBuilder()
97+
98+
// Add features
99+
val features =
100+
if (cucumberOptions.features.nonEmpty) cucumberOptions.features
101+
else List("classpath:" + packageName.replace('.', '/'))
102+
103+
features.foreach { feature =>
104+
builder.addFeature(
105+
io.cucumber.core.feature.FeatureWithLines.parse(feature)
106+
)
107+
}
108+
109+
// Add glue
110+
val glue =
111+
if (cucumberOptions.glue.nonEmpty) cucumberOptions.glue
112+
else List(packageName)
113+
114+
glue.foreach { g =>
115+
builder.addGlue(java.net.URI.create("classpath:" + g))
107116
}
117+
118+
// Add plugins
119+
cucumberOptions.plugin.foreach { p =>
120+
builder.addPluginName(p)
121+
}
122+
123+
builder.build()
108124
}
109125
}

examples/examples-scalatest/src/test/scala/cucumber/examples/scalacalculator/RunCukesTest.scala

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ package cucumber.examples.scalacalculator
22

33
import io.cucumber.scalatest.{CucumberOptions, CucumberSuite}
44

5-
@CucumberOptions(
6-
features = Array("classpath:cucumber/examples/scalacalculator"),
7-
glue = Array("cucumber.examples.scalacalculator"),
8-
plugin = Array("pretty")
9-
)
10-
class RunCukesTest extends CucumberSuite
5+
class RunCukesTest extends CucumberSuite {
6+
override val cucumberOptions = CucumberOptions(
7+
features = List("classpath:cucumber/examples/scalacalculator"),
8+
glue = List("cucumber.examples.scalacalculator"),
9+
plugin = List("pretty")
10+
)
11+
}

integration-tests/scalatest/src/test/resources/cukes/cukes.feature

Lines changed: 0 additions & 89 deletions
This file was deleted.

0 commit comments

Comments
 (0)