From 6a048f454f28eef7095ba8bf0ad4680385e1ca7a Mon Sep 17 00:00:00 2001 From: takahirom Date: Wed, 31 Jul 2024 10:53:09 +0900 Subject: [PATCH] Make it an error when there is no "isShould" and "describe" block --- .../io/github/takahirom/robospec/DescribeBehaviors.kt | 7 ++++++- .../kotlin/io/github/takahirom/robospec/DSLBehaviorTest.kt | 5 ++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/robospec/src/commonMain/kotlin/io/github/takahirom/robospec/DescribeBehaviors.kt b/robospec/src/commonMain/kotlin/io/github/takahirom/robospec/DescribeBehaviors.kt index 6e78ac7..f23986d 100644 --- a/robospec/src/commonMain/kotlin/io/github/takahirom/robospec/DescribeBehaviors.kt +++ b/robospec/src/commonMain/kotlin/io/github/takahirom/robospec/DescribeBehaviors.kt @@ -119,6 +119,11 @@ class BehaviorsTreeBuilder(private val parentDescription: String = "") { children.add(TestNode.ItShould(description) { describedBehavior -> action(describedBehavior) }) } - fun build(name: String): TestNode.Describe = TestNode.Describe(name, children) + fun build(name: String): TestNode.Describe { + if (children.all { it is TestNode.DoIt }) { + throw IllegalStateException("No itShould or describe block found for $name. Please add itShould or describe block, otherwise, it will not be executed.") + } + return TestNode.Describe(name, children) + } } diff --git a/robospec/src/jvmTest/kotlin/io/github/takahirom/robospec/DSLBehaviorTest.kt b/robospec/src/jvmTest/kotlin/io/github/takahirom/robospec/DSLBehaviorTest.kt index 1a24fe8..c5fde86 100644 --- a/robospec/src/jvmTest/kotlin/io/github/takahirom/robospec/DSLBehaviorTest.kt +++ b/robospec/src/jvmTest/kotlin/io/github/takahirom/robospec/DSLBehaviorTest.kt @@ -4,12 +4,11 @@ import kotlinx.coroutines.runBlocking import org.junit.Test class DSLBehaviorTest { - @Test - fun `when just using describe behavior with doIt it should not run`() { + @Test(expected = IllegalStateException::class) + fun `when just using describe behavior with doIt it should be error`() { runBlocking { describeBehaviors("root") { doIt { - error("should not be called") } }.forEach { it.execute(Unit) } }