-
Notifications
You must be signed in to change notification settings - Fork 29
✨ feat: implement scalatest integration #373
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
gaeljw
wants to merge
1
commit into
main
Choose a base branch
from
gh255
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
integration-tests/scalatest/src/test/resources/cukes/cukes.feature
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
Feature: Cukes | ||
|
||
Scenario: in the belly | ||
Given I have 4 "cukes" in my belly | ||
Then I am "happy" | ||
|
||
Scenario: Int in the belly | ||
Given I have eaten an int 100 | ||
Then I should have one hundred in my belly | ||
|
||
Scenario: Long in the belly | ||
Given I have eaten a long 100 | ||
Then I should have long one hundred in my belly | ||
|
||
Scenario: String in the belly | ||
Given I have eaten "numnumnum" | ||
Then I should have numnumnum in my belly | ||
|
||
Scenario: Double in the belly | ||
Given I have eaten 1.5 doubles | ||
Then I should have one and a half doubles in my belly | ||
|
||
Scenario: Float in the belly | ||
Given I have eaten 1.5 floats | ||
Then I should have one and a half floats in my belly | ||
|
||
Scenario: Short in the belly | ||
Given I have eaten a short 100 | ||
Then I should have short one hundred in my belly | ||
|
||
Scenario: Byte in the belly | ||
Given I have eaten a byte 2 | ||
Then I should have two byte in my belly | ||
|
||
Scenario: BigDecimal in the belly | ||
Given I have eaten 1.5 big decimals | ||
Then I should have one and a half big decimals in my belly | ||
|
||
Scenario: BigInt in the belly | ||
Given I have eaten 10 big int | ||
Then I should have a ten big int in my belly | ||
|
||
Scenario: Char in the belly | ||
Given I have eaten char 'C' | ||
Then I should have character C in my belly | ||
|
||
Scenario: Boolean in the belly | ||
Given I have eaten boolean true | ||
Then I should have truth in my belly | ||
|
||
Scenario: DataTable in the belly | ||
Given I have the following foods : | ||
| FOOD | CALORIES | | ||
| cheese | 500 | | ||
| burger | 1000 | | ||
| fries | 750 | | ||
Then I am "definitely happy" | ||
And have eaten 2250.0 calories today | ||
|
||
Scenario: DataTable with args in the belly | ||
Given I have a table the sum of all rows should be 400 : | ||
| ROW | | ||
| 20 | | ||
| 80 | | ||
| 300 | | ||
|
||
Scenario: Argh! a snake - to be custom mapped | ||
Given I see in the distance ... =====> | ||
Then I have a snake of length 6 moving east | ||
And I see in the distance ... <==================== | ||
Then I have a snake of length 21 moving west | ||
|
||
Scenario: Custom object with string constructor | ||
Given I have a person Bob | ||
Then he should say "Hello, I'm Bob!" | ||
|
||
Scenario: Custom objects in the belly | ||
Given I have eaten the following cukes | ||
| Color | Number | | ||
| Green | 1 | | ||
| Red | 3 | | ||
| Blue | 2 | | ||
Then I should have eaten 6 cukes | ||
And they should have been Green, Red, Blue | ||
|
||
Scenario: Did you know that we can handle call by name and zero arity | ||
Given I drink gin and vermouth | ||
When I shake my belly | ||
Then I should have lots of martinis |
10 changes: 10 additions & 0 deletions
10
integration-tests/scalatest/src/test/scala/RunCukesTest.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package cukes | ||
|
||
import io.cucumber.scalatest.{CucumberSuite, CucumberSuiteOptions} | ||
|
||
class RunCukesTest extends CucumberSuite with CucumberSuiteOptions { | ||
|
||
override def featuresPath: Seq[String] = Nil | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what about Functor Option to express something that could be ... could be |
||
|
||
override def gluePackages: Seq[String] = Nil | ||
} |
185 changes: 185 additions & 0 deletions
185
integration-tests/scalatest/src/test/scala/StepDefs.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,185 @@ | ||
import io.cucumber.datatable.DataTable | ||
import io.cucumber.scala.{EN, ScalaDsl} | ||
import model.{Cukes, Person, Snake} | ||
import org.junit.Assert.assertEquals | ||
|
||
import java.util.{List => JList, Map => JMap} | ||
import scala.annotation.nowarn | ||
import scala.jdk.CollectionConverters._ | ||
|
||
/** Test step definitions to exercise Scala cucumber | ||
*/ | ||
@nowarn | ||
class CukesStepDefinitions extends ScalaDsl with EN { | ||
|
||
var calorieCount = 0.0 | ||
var intBelly: Int = 0 | ||
var longBelly: Long = 0L | ||
var stringBelly: String = "" | ||
var doubleBelly: Double = 0.0 | ||
var floatBelly: Float = 0.0f | ||
var shortBelly: Short = 0.toShort | ||
var byteBelly: Byte = 0.toByte | ||
var bigDecimalBelly: BigDecimal = BigDecimal(0) | ||
var bigIntBelly: BigInt = BigInt(0) | ||
var charBelly: Char = 'A' | ||
var boolBelly: Boolean = false | ||
var snake: Snake = null | ||
var person: Person = null | ||
var cukes: JList[Cukes] = null | ||
var gin: Int = 13 | ||
var vermouth: Int = 42 | ||
var maritinis: Int = 0 | ||
|
||
Given("""I have {} {string} in my belly""") { (howMany: Int, what: String) => | ||
} | ||
|
||
Given("""^I have the following foods :$""") { (table: DataTable) => | ||
val maps: JList[JMap[String, String]] = | ||
table.asMaps(classOf[String], classOf[String]) | ||
calorieCount = | ||
maps.asScala.map(_.get("CALORIES")).map(_.toDouble).fold(0.0)(_ + _) | ||
} | ||
And("""have eaten {double} calories today""") { (calories: Double) => | ||
assertEquals(calories, calorieCount, 0.0) | ||
} | ||
|
||
Given("""I have eaten an int {int}""") { (arg0: Int) => | ||
intBelly = arg0 | ||
} | ||
Then("""^I should have one hundred in my belly$""") { () => | ||
assertEquals(100, intBelly) | ||
} | ||
|
||
Given("""I have eaten a long {long}""") { (arg0: Long) => | ||
longBelly = arg0 | ||
} | ||
Then("""^I should have long one hundred in my belly$""") { () => | ||
assertEquals(100L, longBelly) | ||
} | ||
|
||
Given("""^I have eaten "(.*)"$""") { (arg0: String) => | ||
stringBelly = arg0 | ||
} | ||
Then("""^I should have numnumnum in my belly$""") { () => | ||
assertEquals("numnumnum", stringBelly) | ||
} | ||
|
||
Given("""I have eaten {double} doubles""") { (arg0: Double) => | ||
doubleBelly = arg0 | ||
} | ||
Then("""^I should have one and a half doubles in my belly$""") { () => | ||
assertEquals(1.5, doubleBelly, 0.0) | ||
} | ||
|
||
Given("""I have eaten {} floats""") { (arg0: Float) => | ||
floatBelly = arg0 | ||
} | ||
Then("""^I should have one and a half floats in my belly$""") { () => | ||
assertEquals(1.5f, floatBelly, 0.0) | ||
} | ||
|
||
Given("""I have eaten a short {short}""") { (arg0: Short) => | ||
shortBelly = arg0 | ||
} | ||
Then("""^I should have short one hundred in my belly$""") { () => | ||
assertEquals(100.toShort, shortBelly) | ||
} | ||
|
||
Given("""I have eaten a byte {byte}""") { (arg0: Byte) => | ||
byteBelly = arg0 | ||
} | ||
Then("""^I should have two byte in my belly$""") { () => | ||
assertEquals(2.toByte, byteBelly) | ||
} | ||
|
||
Given("""I have eaten {bigdecimal} big decimals""") { | ||
(arg0: java.math.BigDecimal) => | ||
bigDecimalBelly = arg0 | ||
} | ||
Then("""^I should have one and a half big decimals in my belly$""") { () => | ||
assertEquals(BigDecimal(1.5), bigDecimalBelly) | ||
} | ||
|
||
Given("""I have eaten {biginteger} big int""") { | ||
(arg0: java.math.BigInteger) => | ||
bigIntBelly = arg0.intValue() | ||
} | ||
Then("""^I should have a ten big int in my belly$""") { () => | ||
assertEquals(BigInt(10), bigIntBelly) | ||
} | ||
|
||
Given("""I have eaten char '{char}'""") { (arg0: Char) => | ||
charBelly = 'C' | ||
} | ||
Then("""^I should have character C in my belly$""") { () => | ||
assertEquals('C', charBelly) | ||
} | ||
|
||
Given("""I have eaten boolean {boolean}""") { (arg0: Boolean) => | ||
boolBelly = arg0 | ||
} | ||
Then("""^I should have truth in my belly$""") { () => | ||
assertEquals(true, boolBelly) | ||
} | ||
|
||
Given("""I have a table the sum of all rows should be {int} :""") { | ||
(value: Int, table: DataTable) => | ||
assertEquals( | ||
value, | ||
table | ||
.asList(classOf[String]) | ||
.asScala | ||
.drop(1) | ||
.map(String.valueOf(_: String).toInt) | ||
.foldLeft(0)(_ + _) | ||
) | ||
} | ||
|
||
Given("""I see in the distance ... {snake}""") { (s: Snake) => | ||
snake = s | ||
} | ||
Then("""^I have a snake of length (\d+) moving (.*)$""") { | ||
(size: Int, dir: String) => | ||
assertEquals(size, snake.length) | ||
assertEquals(Symbol(dir), snake.direction) | ||
} | ||
|
||
Given("""I have a person {person}""") { (p: Person) => | ||
person = p | ||
} | ||
|
||
Then("""^he should say \"(.*)\"""") { (s: String) => | ||
assertEquals(person.hello, s) | ||
} | ||
|
||
Given("^I have eaten the following cukes$") { (cs: JList[Cukes]) => | ||
cukes = cs | ||
} | ||
|
||
Then("""I should have eaten {int} cukes""") { (total: Int) => | ||
assertEquals(total, cukes.asScala.map(_.number).sum) | ||
} | ||
|
||
And("^they should have been (.*)$") { (colors: String) => | ||
assertEquals(colors, cukes.asScala.map(_.color).mkString(", ")) | ||
} | ||
|
||
Given("^I drink gin and vermouth$") { () => | ||
gin = 13 | ||
vermouth = 42 | ||
} | ||
|
||
When("^I shake my belly$") { // note the lack of () => | ||
maritinis += vermouth * gin | ||
} | ||
|
||
Then("^I should have lots of martinis$") { () => | ||
assertEquals(13 * 42, maritinis) | ||
} | ||
} | ||
|
||
@nowarn | ||
class ThenDefs extends ScalaDsl with EN { | ||
Then("""^I am "([^"]*)"$""") { (arg0: String) => } | ||
} |
39 changes: 39 additions & 0 deletions
39
integration-tests/scalatest/src/test/scala/TypeRegistryConfiguration.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import io.cucumber.scala.ScalaDsl | ||
import model.{Cukes, Person, Snake} | ||
|
||
class TypeRegistryConfiguration extends ScalaDsl { | ||
|
||
/** Transforms an ASCII snake into an object, for example: | ||
* | ||
* {{{ | ||
* ====> becomes Snake(length = 5, direction = 'east) | ||
* ==> becomes Snake(length = 3, direction = 'east) | ||
* }}} | ||
*/ | ||
ParameterType("snake", "[=><]+") { s => | ||
val size = s.length | ||
val direction = s.toList match { | ||
case '<' :: _ => Symbol("west") | ||
case l if l.last == '>' => Symbol("east") | ||
case _ => Symbol("unknown") | ||
} | ||
Snake(size, direction) | ||
} | ||
|
||
ParameterType("person", ".+") { s => | ||
Person(s) | ||
} | ||
|
||
ParameterType("boolean", "true|false") { s => | ||
s.trim.equals("true") | ||
} | ||
|
||
ParameterType("char", ".") { s => | ||
s.charAt(0) | ||
} | ||
|
||
DataTableType { (map: Map[String, String]) => | ||
Cukes(map("Number").toInt, map("Color")) | ||
} | ||
|
||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.