-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathLambdaStepDefinitions.kt
More file actions
74 lines (57 loc) · 2.2 KB
/
LambdaStepDefinitions.kt
File metadata and controls
74 lines (57 loc) · 2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package io.cucumber.kotlin
import io.cucumber.datatable.DataTable
import io.cucumber.java8.En
import io.cucumber.java8.Scenario
import org.junit.jupiter.api.Assertions.*
import org.opentest4j.TestAbortedException
var lastInstance: LambdaStepDefinitions? = null
class LambdaStepDefinitions : En {
init {
DataTableType { entry: Map<String, String> ->
Person(entry["first"], entry["last"])
}
Before { scenario: Scenario ->
assertNotSame(this, lastInstance)
lastInstance = this
}
BeforeStep { scenario: Scenario ->
assertSame(this, lastInstance)
lastInstance = this
}
AfterStep { scenario: Scenario ->
assertSame(this, lastInstance)
lastInstance = this
}
After { scenario: Scenario ->
assertSame(this, lastInstance)
lastInstance = this
}
Given("this data table:") { peopleTable: DataTable ->
val people: List<Person?> = peopleTable.asList(Person::class.java)
assertEquals("Aslak", people[0]!!.first)
assertEquals("Hellesøy", people[0]!!.last)
}
val alreadyHadThisManyCukes = 1
Given("I have {long} cukes in my belly") { n: Long ->
assertEquals(1, alreadyHadThisManyCukes)
assertEquals(42L, n)
}
val localState = "hello"
Then("I really have {int} cukes in my belly") { i: Int ->
assertEquals(42, i)
assertEquals("hello", localState)
}
Given("A statement with a body expression") { assertTrue(true) }
Given("A statement with a simple match", { assertTrue(true) })
Given("something that is skipped") { throw TestAbortedException("skip this!") }
val localInt = 1
Given("A statement with a scoped argument", { assertEquals(2, localInt + 1) })
Given("I will give you {int} and {float} and {word} and {int}") { a: Int, b: Float, c: String, d: Int ->
assertEquals(1, a)
assertEquals(2.2f, b)
assertEquals("three", c)
assertEquals(4, d)
}
}
}
data class Person(val first: String?, val last: String?)