Skip to content

Commit c53e08e

Browse files
Copilotgaeljw
andcommitted
Add cucumber-scalatest example project
Co-authored-by: gaeljw <18280708+gaeljw@users.noreply.github.com>
1 parent e9b91f9 commit c53e08e

File tree

6 files changed

+93
-1
lines changed

6 files changed

+93
-1
lines changed

build.sbt

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ lazy val root = (project in file("."))
9494
integrationTestsPicoContainer.projectRefs ++
9595
integrationTestsScalatest.projectRefs ++
9696
examplesJunit4.projectRefs ++
97-
examplesJunit5.projectRefs: _*
97+
examplesJunit5.projectRefs ++
98+
examplesScalatest.projectRefs: _*
9899
)
99100

100101
// Main project
@@ -275,6 +276,20 @@ lazy val examplesJunit5 = (projectMatrix in file("examples/examples-junit5"))
275276
.dependsOn(cucumberScala % Test)
276277
.jvmPlatform(scalaVersions = Seq(scala3, scala213))
277278

279+
lazy val examplesScalatest = (projectMatrix in file("examples/examples-scalatest"))
280+
.settings(commonSettings)
281+
.settings(scalatestSbtSupport)
282+
.settings(
283+
name := "scala-examples-scalatest",
284+
libraryDependencies ++= Seq(
285+
"org.scalatest" %% "scalatest" % scalatestVersion % Test
286+
),
287+
publishArtifact := false
288+
)
289+
.dependsOn(cucumberScala % Test)
290+
.dependsOn(cucumberScalatest % Test)
291+
.jvmPlatform(scalaVersions = Seq(scala3, scala213))
292+
278293
// Version policy check
279294

280295
ThisBuild / versionScheme := Some("early-semver")
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package cucumber.examples.scalacalculator
2+
3+
import scala.collection.mutable.Queue
4+
5+
sealed trait Arg
6+
7+
object Arg {
8+
implicit def op(s: String): Op = Op(s)
9+
implicit def value(v: Double): Val = Val(v)
10+
}
11+
12+
case class Op(value: String) extends Arg
13+
case class Val(value: Double) extends Arg
14+
15+
class RpnCalculator {
16+
private val stack = Queue.empty[Double]
17+
18+
private def op(f: (Double, Double) => Double) =
19+
stack += f(stack.dequeue(), stack.dequeue())
20+
21+
def push(arg: Arg): Unit = {
22+
arg match {
23+
case Op("+") => op(_ + _)
24+
case Op("-") => op(_ - _)
25+
case Op("*") => op(_ * _)
26+
case Op("/") => op(_ / _)
27+
case Val(value) => stack += value
28+
case _ => ()
29+
}
30+
()
31+
}
32+
33+
def value: Double = stack.head
34+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
@foo
2+
Feature: Basic Arithmetic
3+
4+
Scenario: Adding
5+
# Try to change one of the values below to provoke a failure
6+
When I add 4.0 and 5.0
7+
Then the result is 9.0
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
cucumber.plugin=pretty
2+
# Workaround for https://github.com/sbt/sbt-jupiter-interface/issues/142
3+
# See also https://github.com/cucumber/cucumber-jvm/pull/3023
4+
cucumber.junit-platform.discovery.as-root-engine=false
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package cucumber.examples.scalacalculator
2+
3+
import io.cucumber.scala.{EN, ScalaDsl, Scenario}
4+
5+
class RpnCalculatorStepDefinitions extends ScalaDsl with EN {
6+
7+
val calc = new RpnCalculator
8+
9+
When("""I add {double} and {double}""") { (arg1: Double, arg2: Double) =>
10+
calc push arg1
11+
calc push arg2
12+
calc push "+"
13+
}
14+
15+
Then("the result is {double}") { (expected: Double) =>
16+
assert(math.abs(expected - calc.value) < 0.001, s"Expected $expected but got ${calc.value}")
17+
}
18+
19+
Before("not @foo") { (scenario: Scenario) =>
20+
println(s"Runs before scenarios *not* tagged with @foo (${scenario.getId})")
21+
}
22+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package cucumber.examples.scalacalculator
2+
3+
import io.cucumber.scalatest.{CucumberOptions, CucumberSuite}
4+
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

0 commit comments

Comments
 (0)