Skip to content

Commit 8ef3584

Browse files
committed
Add examples
1 parent 8e9fdb6 commit 8ef3584

File tree

28 files changed

+687
-82
lines changed

28 files changed

+687
-82
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.idea
2+
**/*.iml
3+
**/target/

examples/pom.xml

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
2+
<modelVersion>4.0.0</modelVersion>
3+
4+
<parent>
5+
<groupId>io.cucumber</groupId>
6+
<artifactId>cucumber-jvm-scala</artifactId>
7+
<version>2.0.2-SNAPSHOT</version>
8+
</parent>
9+
10+
<artifactId>scala-examples</artifactId>
11+
<packaging>jar</packaging>
12+
<name>Examples: Scala Calculator</name>
13+
14+
<dependencies>
15+
<dependency>
16+
<groupId>io.cucumber</groupId>
17+
<artifactId>cucumber-scala_2.12</artifactId>
18+
<version>${project.version}</version>
19+
<scope>test</scope>
20+
</dependency>
21+
<dependency>
22+
<groupId>io.cucumber</groupId>
23+
<artifactId>cucumber-junit</artifactId>
24+
<scope>test</scope>
25+
</dependency>
26+
<dependency>
27+
<groupId>junit</groupId>
28+
<artifactId>junit</artifactId>
29+
<scope>test</scope>
30+
</dependency>
31+
<dependency>
32+
<groupId>org.scala-lang</groupId>
33+
<artifactId>scala-library</artifactId>
34+
<version>${scala.2.12.version}</version>
35+
</dependency>
36+
<dependency>
37+
<groupId>org.scala-lang</groupId>
38+
<artifactId>scala-compiler</artifactId>
39+
<version>${scala.2.12.version}</version>
40+
</dependency>
41+
</dependencies>
42+
43+
<build>
44+
<plugins>
45+
<plugin>
46+
<groupId>org.apache.maven.plugins</groupId>
47+
<artifactId>maven-compiler-plugin</artifactId>
48+
<configuration>
49+
<source>1.8</source>
50+
<target>1.8</target>
51+
</configuration>
52+
</plugin>
53+
<plugin>
54+
<artifactId>maven-deploy-plugin</artifactId>
55+
<configuration>
56+
<skip>true</skip>
57+
</configuration>
58+
</plugin>
59+
<plugin>
60+
<groupId>net.alchim31.maven</groupId>
61+
<artifactId>scala-maven-plugin</artifactId>
62+
<configuration>
63+
<!--encoding>UTF-8</encoding-->
64+
<excludes>
65+
<exclude>**/*.java</exclude>
66+
</excludes>
67+
</configuration>
68+
<executions>
69+
<execution>
70+
<goals>
71+
<goal>add-source</goal>
72+
<goal>compile</goal>
73+
<goal>testCompile</goal>
74+
</goals>
75+
</execution>
76+
</executions>
77+
</plugin>
78+
</plugins>
79+
</build>
80+
</project>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package cucumber.examples.scalacalculator
2+
3+
import scala.collection.mutable.Queue
4+
5+
6+
sealed trait Arg
7+
8+
object Arg{
9+
implicit def op(s:String) = Op(s)
10+
implicit def value(v:Double) = Val(v)
11+
}
12+
13+
case class Op(value: String) extends Arg
14+
case class Val(value: Double) extends Arg
15+
16+
class RpnCalculator {
17+
private val stack = new Queue[Double]
18+
19+
private def op(f: (Double, Double) => Double) =
20+
stack += f(stack.dequeue(), stack.dequeue())
21+
22+
def push(arg: Arg) {
23+
arg match {
24+
case Op("+") => op(_ + _)
25+
case Op("-") => op(_ - _)
26+
case Op("*") => op(_ * _)
27+
case Op("/") => op(_ / _)
28+
case Val(value) => stack += value
29+
}
30+
}
31+
32+
def value = stack.head
33+
}
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 and 5
7+
Then the result is 9
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package cucumber.examples.scalacalculator
2+
3+
import cucumber.api.Scenario
4+
import cucumber.api.scala.{ScalaDsl, EN}
5+
import org.junit.Assert._
6+
7+
class RpnCalculatorStepDefinitions extends ScalaDsl with EN {
8+
9+
val calc = new RpnCalculator
10+
11+
When("""^I add (\d+) and (\d+)$"""){ (arg1: Double, arg2: Double) =>
12+
calc push arg1
13+
calc push arg2
14+
calc push "+"
15+
}
16+
17+
Then("^the result is (\\d+)$") { expected: Double =>
18+
assertEquals(expected, calc.value, 0.001)
19+
}
20+
21+
Before("not @foo"){ scenario : Scenario =>
22+
println("Runs before scenarios *not* tagged with @foo")
23+
}
24+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package cucumber.examples.scalacalculator
2+
3+
import org.junit.runner.RunWith
4+
import cucumber.api.junit.Cucumber
5+
6+
@RunWith(classOf[Cucumber])
7+
class RunCukesTest

0 commit comments

Comments
 (0)