Skip to content

Commit 621daa9

Browse files
add support for DescribeSpec
1 parent 6d61837 commit 621daa9

File tree

3 files changed

+81
-40
lines changed

3 files changed

+81
-40
lines changed

src/main/kotlin/io/kotest/plugin/intellij/styles/DescribeSpecStyle.kt

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import io.kotest.plugin.intellij.psi.extractLhsStringArgForDotExpressionWithRhsF
1010
import io.kotest.plugin.intellij.psi.extractStringArgForFunctionWithStringAndLambdaArgs
1111
import io.kotest.plugin.intellij.psi.ifDotExpressionSeparator
1212
import io.kotest.plugin.intellij.psi.ifOpenQuoteOfFunctionName
13+
import io.kotest.plugin.intellij.psi.isDataTestMethodCall
1314
import org.jetbrains.kotlin.name.FqName
1415
import org.jetbrains.kotlin.psi.KtCallExpression
1516
import org.jetbrains.kotlin.psi.KtClassOrObject
@@ -25,6 +26,14 @@ object DescribeSpecStyle : SpecStyle {
2526
return "describe(\"$name\") { }"
2627
}
2728

29+
override fun getDataTestMethodNames(): Set<String> =
30+
setOf(
31+
"withData",
32+
"withContexts",
33+
"withDescribes",
34+
"withIts"
35+
)
36+
2837
private val fnNames = setOf("describe", "xdescribe", "context", "xcontext", "it", "xit")
2938

3039
override fun isTestElement(element: PsiElement): Boolean = test(element) != null
@@ -246,6 +255,7 @@ object DescribeSpecStyle : SpecStyle {
246255
?: element.tryXDescribe()
247256
?: element.tryContext()
248257
?: element.tryXContent()
258+
?: element.tryDataTest()
249259
is KtDotQualifiedExpression ->
250260
element.tryDescribeWithConfig()
251261
?: element.tryXDescribeWithConfig()
@@ -261,13 +271,38 @@ object DescribeSpecStyle : SpecStyle {
261271
return setOf("OPEN_QUOTE", "DOT")
262272
}
263273

274+
/**
275+
* For a DescribeSpec we consider the following scenarios:
276+
*
277+
* describe("test name") { }
278+
* xdescribe("test name") { }
279+
* context("test name") { }
280+
* xcontext("test name") { }
281+
* it("test name") { }
282+
* xit("test name") { }
283+
* describe("test name").config(...) {}
284+
* xdescribe("test name").config(...) {}
285+
* context("test name").config(...) {}
286+
* xcontext("test name").config(...) {}
287+
* it("test name").config(...) {}
288+
* xit("test name").config(...) {}
289+
* withData(...) { }
290+
* withContexts(...) { }
291+
* withDescribes(...) { }
292+
* withIts(...) { }
293+
*/
264294
override fun test(element: LeafPsiElement): Test? {
265295
val call = element.ifOpenQuoteOfFunctionName(fnNames)
266296
if (call != null) return test(call)
267297

268298
val dot = element.ifDotExpressionSeparator()
269299
if (dot != null) return test(dot)
270300

301+
// try to find Data Test Method by finding lambda openings
302+
val dataMethodCall = element.isDataTestMethodCall(ShouldSpecStyle.getDataTestMethodNames())
303+
if (dataMethodCall != null) {
304+
return ShouldSpecStyle.test(dataMethodCall)
305+
}
271306
return null
272307
}
273308
}

src/test/kotlin/io/kotest/plugin/intellij/styles/DescribeSpecRunMarkerTest.kt

Lines changed: 41 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -33,82 +33,83 @@ class DescribeSpecRunMarkerTest : LightJavaCodeInsightFixtureTestCase() {
3333
val gutters = myFixture.findAllGutters()
3434

3535
val expected = listOf(
36-
Gutter("Run DescribeSpecExample", 91, AllIcons.RunConfigurations.TestState.Run_run),
37-
Gutter("Run describe block", 161),
38-
Gutter("Run describe block it block", 193),
39-
Gutter("Disabled - describe block xit block", 256, AllIcons.RunConfigurations.TestIgnored),
40-
Gutter("Run describe block it with config", 336),
41-
Gutter("Disabled - describe block xit block with config", 436, AllIcons.RunConfigurations.TestIgnored),
42-
Gutter("Run describe block nested describe block", 517),
43-
Gutter("Run describe block nested describe block it block", 559),
44-
Gutter("Disabled - describe block nested xdescribe block", 645, AllIcons.RunConfigurations.TestIgnored),
36+
Gutter("Run DescribeSpecExample", 126, AllIcons.RunConfigurations.TestState.Run_run),
37+
Gutter("Run describe block", 196),
38+
Gutter("Run describe block it block", 228),
39+
Gutter("Disabled - describe block xit block", 291, AllIcons.RunConfigurations.TestIgnored),
40+
Gutter("Run describe block it with config", 371),
41+
Gutter("Disabled - describe block xit block with config", 471, AllIcons.RunConfigurations.TestIgnored),
42+
Gutter("Run describe block nested describe block", 552),
43+
Gutter("Run describe block nested describe block it block", 594),
44+
Gutter("Disabled - describe block nested xdescribe block", 680, AllIcons.RunConfigurations.TestIgnored),
4545
Gutter(
4646
"Disabled - describe block nested xdescribe block it block",
47-
688,
47+
723,
4848
AllIcons.RunConfigurations.TestIgnored
4949
),
50-
Gutter("Disabled - xdescribe block", 779, AllIcons.RunConfigurations.TestIgnored),
51-
Gutter("Disabled - xdescribe block it block", 812, AllIcons.RunConfigurations.TestIgnored),
52-
Gutter("Disabled - xdescribe block xit block", 875, AllIcons.RunConfigurations.TestIgnored),
53-
Gutter("Disabled - xdescribe block it with config", 955, AllIcons.RunConfigurations.TestIgnored),
54-
Gutter("Disabled - xdescribe block xit block with config", 1055, AllIcons.RunConfigurations.TestIgnored),
55-
Gutter("Disabled - xdescribe block nested describe block", 1136, AllIcons.RunConfigurations.TestIgnored),
50+
Gutter("Disabled - xdescribe block", 814, AllIcons.RunConfigurations.TestIgnored),
51+
Gutter("Disabled - xdescribe block it block", 847, AllIcons.RunConfigurations.TestIgnored),
52+
Gutter("Disabled - xdescribe block xit block", 910, AllIcons.RunConfigurations.TestIgnored),
53+
Gutter("Disabled - xdescribe block it with config", 990, AllIcons.RunConfigurations.TestIgnored),
54+
Gutter("Disabled - xdescribe block xit block with config", 1090, AllIcons.RunConfigurations.TestIgnored),
55+
Gutter("Disabled - xdescribe block nested describe block", 1171, AllIcons.RunConfigurations.TestIgnored),
5656
Gutter(
5757
"Disabled - xdescribe block nested describe block it block",
58-
1178,
58+
1213,
5959
AllIcons.RunConfigurations.TestIgnored
6060
),
61-
Gutter("Disabled - xdescribe block nested xdescribe block", 1264, AllIcons.RunConfigurations.TestIgnored),
61+
Gutter("Disabled - xdescribe block nested xdescribe block", 1299, AllIcons.RunConfigurations.TestIgnored),
6262
Gutter(
6363
"Disabled - xdescribe block nested xdescribe block it block",
64-
1307,
64+
1342,
6565
AllIcons.RunConfigurations.TestIgnored
6666
),
67-
Gutter("Run context block", 1396),
68-
Gutter("Run context block nested context block", 1432),
69-
Gutter("Run context block nested context block nested describe block", 1479),
70-
Gutter("Run context block nested context block nested describe block it block", 1524),
67+
Gutter("Run context block", 1431),
68+
Gutter("Run context block nested context block", 1467),
69+
Gutter("Run context block nested context block nested describe block", 1514),
70+
Gutter("Run context block nested context block nested describe block it block", 1559),
7171
Gutter(
7272
"Disabled - context block nested context block nested xdescribe block",
73-
1622,
73+
1657,
7474
AllIcons.RunConfigurations.TestIgnored
7575
),
7676
Gutter(
7777
"Disabled - context block nested context block nested xdescribe block it block",
78-
1668,
78+
1703,
7979
AllIcons.RunConfigurations.TestIgnored
8080
),
81-
Gutter("Disabled - context block nested xcontext block", 1773, AllIcons.RunConfigurations.TestIgnored),
81+
Gutter("Disabled - context block nested xcontext block", 1808, AllIcons.RunConfigurations.TestIgnored),
8282
Gutter(
8383
"Disabled - context block nested xcontext block nested describe block",
84-
1821,
84+
1856,
8585
AllIcons.RunConfigurations.TestIgnored
8686
),
8787
Gutter(
8888
"Disabled - context block nested xcontext block nested describe block it block",
89-
1866,
89+
1901,
9090
AllIcons.RunConfigurations.TestIgnored
9191
),
9292
Gutter(
9393
"Disabled - context block nested xcontext block nested xdescribe block",
94-
1964,
94+
1999,
9595
AllIcons.RunConfigurations.TestIgnored
9696
),
9797
Gutter(
9898
"Disabled - context block nested xcontext block nested xdescribe block it block",
99-
2010,
99+
2045,
100100
AllIcons.RunConfigurations.TestIgnored
101101
),
102-
Gutter("Run context block nested describe block", 2115),
103-
Gutter("Run context block nested describe block it block", 2157),
104-
Gutter("Run describe with config", 2270),
105-
Gutter("Run describe with config it block", 2308),
106-
Gutter("Disabled - xdescribe with config", 2406, AllIcons.RunConfigurations.TestIgnored),
107-
Gutter("Disabled - xdescribe with config it block", 2444, AllIcons.RunConfigurations.TestIgnored),
108-
Gutter("Run context with config", 2538),
109-
Gutter("Run context with config nested describe with config", 2612),
110-
Gutter("Run context with config nested describe with config it block", 2653),
111-
Gutter("Disabled - xcontext with config", 2766, AllIcons.RunConfigurations.TestIgnored),
102+
Gutter("Run context block nested describe block", 2150),
103+
Gutter("Run context block nested describe block it block", 2192),
104+
Gutter("Run describe with config", 2305),
105+
Gutter("Run describe with config it block", 2343),
106+
Gutter("Disabled - xdescribe with config", 2441, AllIcons.RunConfigurations.TestIgnored),
107+
Gutter("Disabled - xdescribe with config it block", 2479, AllIcons.RunConfigurations.TestIgnored),
108+
Gutter("Run context with config", 2573),
109+
Gutter("Run context with config nested describe with config", 2647),
110+
Gutter("Run context with config nested describe with config it block", 2688),
111+
Gutter("Disabled - xcontext with config", 2801, AllIcons.RunConfigurations.TestIgnored),
112+
Gutter("Run All Spec Tests, including data tests", 2866),
112113
)
113114

114115
expected.size shouldBe gutters.size

src/test/resources/describespec.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.sksamuel.kotest.specs.describe
22

33
import io.kotest.core.spec.style.DescribeSpec
4+
import io.kotest.datatest.withData
45

56
class DescribeSpecExample : DescribeSpec() {
67
init {
@@ -102,6 +103,10 @@ class DescribeSpecExample : DescribeSpec() {
102103
}
103104
xcontext("xcontext with config").config(enabled = true) {
104105
}
106+
107+
withData(1, 2, 3, 4, 5) { value ->
108+
// test here
109+
}
105110
}
106111
}
107112

0 commit comments

Comments
 (0)