Skip to content

Commit

Permalink
Merge pull request #4 from takahirom/takahirom/make-it-error-when-the…
Browse files Browse the repository at this point in the history
…re-is-no-itShould-and-describe-block/2024-07-31

Make it an error when there is no "isShould" and "describe" block
  • Loading branch information
takahirom authored Jul 31, 2024
2 parents d732963 + 6a048f4 commit e9be70a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ class BehaviorsTreeBuilder<T>(private val parentDescription: String = "") {
children.add(TestNode.ItShould(description) { describedBehavior -> action(describedBehavior) })
}

fun build(name: String): TestNode.Describe<T> = TestNode.Describe(name, children)
fun build(name: String): TestNode.Describe<T> {
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)
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -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<Unit>("root") {
doIt {
error("should not be called")
}
}.forEach { it.execute(Unit) }
}
Expand Down

0 comments on commit e9be70a

Please sign in to comment.