-
Notifications
You must be signed in to change notification settings - Fork 180
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce fixture aliases for Gherkin style (#818)
- Loading branch information
Showing
4 changed files
with
170 additions
and
1 deletion.
There are no files selected for viewing
60 changes: 60 additions & 0 deletions
60
integration-test/src/jvmTest/kotlin/org/spekframework/spek2/FakeGroupBody.kt
This file contains 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,60 @@ | ||
package org.spekframework.spek2 | ||
|
||
|
||
import org.spekframework.spek2.dsl.Fixture | ||
import org.spekframework.spek2.dsl.GroupBody | ||
import org.spekframework.spek2.dsl.Skip | ||
import org.spekframework.spek2.dsl.TestBody | ||
import org.spekframework.spek2.lifecycle.CachingMode | ||
import org.spekframework.spek2.lifecycle.MemoizedValue | ||
|
||
class FakeGroupBody : GroupBody { | ||
var beforeEachGroup: Fixture? = null | ||
var afterEachGroup: Fixture? = null | ||
var beforeGroup: Fixture? = null | ||
var afterGroup: Fixture? = null | ||
var beforeEachTest: Fixture? = null | ||
var afterEachTest: Fixture? = null | ||
|
||
override fun group(description: String, skip: Skip, defaultCachingMode: CachingMode, preserveExecutionOrder: Boolean, failFast: Boolean, body: GroupBody.() -> Unit) = | ||
throw UnsupportedOperationException() | ||
|
||
override val defaultCachingMode: CachingMode | ||
get() = throw UnsupportedOperationException() | ||
|
||
override fun <T> memoized(mode: CachingMode, factory: () -> T): MemoizedValue<T> = | ||
throw UnsupportedOperationException() | ||
|
||
override fun <T> memoized(mode: CachingMode, factory: () -> T, destructor: (T) -> Unit): MemoizedValue<T> = | ||
throw UnsupportedOperationException() | ||
|
||
override fun beforeEachTest(fixture: Fixture) { | ||
beforeEachTest = fixture | ||
} | ||
|
||
override fun afterEachTest(fixture: Fixture) { | ||
afterEachTest = fixture | ||
} | ||
|
||
override fun beforeEachGroup(fixture: Fixture) { | ||
beforeEachGroup = fixture | ||
} | ||
|
||
override fun afterEachGroup(fixture: Fixture) { | ||
afterEachGroup = fixture | ||
} | ||
|
||
override fun beforeGroup(fixture: Fixture) { | ||
beforeGroup = fixture | ||
} | ||
|
||
override fun afterGroup(fixture: Fixture) { | ||
afterGroup = fixture | ||
} | ||
|
||
override fun <T> memoized(): MemoizedValue<T> = throw UnsupportedOperationException() | ||
|
||
override var defaultTimeout: Long = 0L | ||
|
||
override fun test(description: String, skip: Skip, timeout: Long, body: TestBody.() -> Unit) = throw UnsupportedOperationException() | ||
} |
34 changes: 34 additions & 0 deletions
34
integration-test/src/jvmTest/kotlin/org/spekframework/spek2/FeatureBodyAliasesTest.kt
This file contains 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,34 @@ | ||
package org.spekframework.spek2 | ||
|
||
import org.spekframework.spek2.style.gherkin.FeatureBody | ||
import kotlin.test.assertSame | ||
|
||
object FeatureBodyAliasesTest : Spek({ | ||
|
||
val groupBody by memoized { FakeGroupBody() } | ||
val featureBody by memoized { FeatureBody(groupBody) } | ||
|
||
test("beforeEachScenario should call beforeEachGroup") { | ||
val fixture = { println("hello") } | ||
featureBody.beforeEachScenario(fixture) | ||
assertSame(fixture, groupBody.beforeEachGroup) | ||
} | ||
|
||
test("afterEachScenario should call AfterEachGroup") { | ||
val fixture = { println("hello") } | ||
featureBody.afterEachScenario(fixture) | ||
assertSame(fixture, groupBody.afterEachGroup) | ||
} | ||
|
||
test("beforeFeature should call BeforeGroup") { | ||
val fixture = { println("hello") } | ||
featureBody.beforeFeature(fixture) | ||
assertSame(fixture, groupBody.beforeGroup) | ||
} | ||
|
||
test("afterFeature should call AfterGroup") { | ||
val fixture = { println("hello") } | ||
featureBody.afterFeature(fixture) | ||
assertSame(fixture, groupBody.afterGroup) | ||
} | ||
}) |
35 changes: 35 additions & 0 deletions
35
integration-test/src/jvmTest/kotlin/org/spekframework/spek2/ScenarioBodyAliasesTest.kt
This file contains 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,35 @@ | ||
package org.spekframework.spek2 | ||
|
||
|
||
import org.spekframework.spek2.style.gherkin.ScenarioBody | ||
import kotlin.test.assertSame | ||
|
||
object ScenarioBodyAliasesTest : Spek({ | ||
|
||
val groupBody by memoized { FakeGroupBody() } | ||
val scenarioBody by memoized { ScenarioBody(groupBody) } | ||
|
||
test("beforeEachScenario should call BeforeEachGroup") { | ||
val fixture = { println("hello") } | ||
scenarioBody.beforeScenario(fixture) | ||
assertSame(fixture, groupBody.beforeGroup) | ||
} | ||
|
||
test("afterEachScenario should call AfterEachGroup") { | ||
val fixture = { println("hello") } | ||
scenarioBody.afterScenario(fixture) | ||
assertSame(fixture, groupBody.afterGroup) | ||
} | ||
|
||
test("beforeEachStep should call BeforeEachTest") { | ||
val fixture = { println("hello") } | ||
scenarioBody.beforeEachStep(fixture) | ||
assertSame(fixture, groupBody.beforeEachTest) | ||
} | ||
|
||
test("afterEachStep should call AfterEachTest") { | ||
val fixture = { println("hello") } | ||
scenarioBody.afterEachStep(fixture) | ||
assertSame(fixture, groupBody.afterEachTest) | ||
} | ||
}) |
This file contains 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