forked from spekframework/spek
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This introduces extensions in Spek, see spekframework#115 on how to implement one. It also includes the following changes: - Renamed several DSL classes (breaking change) - Reworked subject support as an extension - Rebrand lazy groups to action groups
- Loading branch information
Showing
75 changed files
with
883 additions
and
1,172 deletions.
There are no files selected for viewing
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,11 @@ | ||
== Changelog | ||
|
||
Releases:: | ||
1.1.0::: | ||
* Renamed `Dsl` to `SpecBody`. | ||
* Added support for extensions. | ||
* Reworked subjects as an extension. | ||
* Support specs defined as objects. | ||
|
||
1.0.0::: | ||
* Initial release of Spek. |
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
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
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
14 changes: 14 additions & 0 deletions
14
spek-api/src/main/kotlin/org/jetbrains/spek/api/CreateWith.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,14 @@ | ||
package org.jetbrains.spek.api | ||
|
||
import org.jetbrains.spek.api.lifecycle.InstanceFactory | ||
import java.lang.annotation.Inherited | ||
import kotlin.reflect.KClass | ||
|
||
/** | ||
* @author Ranie Jade Ramiso | ||
* @since 1.1 | ||
*/ | ||
@Target(AnnotationTarget.CLASS) | ||
@Retention(AnnotationRetention.RUNTIME) | ||
@Inherited | ||
annotation class CreateWith(val factory: KClass<out InstanceFactory>) |
7 changes: 5 additions & 2 deletions
7
...lin/org/jetbrains/spek/api/SubjectSpek.kt → ...n/kotlin/org/jetbrains/spek/api/Shared.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 |
---|---|---|
@@ -1,10 +1,13 @@ | ||
package org.jetbrains.spek.api | ||
|
||
import org.jetbrains.spek.api.dsl.SubjectDsl | ||
import org.jetbrains.spek.api.dsl.Spec | ||
import org.jetbrains.spek.meta.Experimental | ||
|
||
/** | ||
* @author Ranie Jade Ramiso | ||
* @since 1.1 | ||
*/ | ||
@Experimental | ||
abstract class SubjectSpek<T>(val spec: SubjectDsl<T>.() -> Unit) | ||
fun Spec.include(spec: Spek) { | ||
spec.spec(this) | ||
} |
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 |
---|---|---|
@@ -1,9 +1,13 @@ | ||
package org.jetbrains.spek.api | ||
|
||
import org.jetbrains.spek.api.dsl.Dsl | ||
import org.jetbrains.spek.api.dsl.Spec | ||
|
||
/** | ||
* @author Ranie Jade Ramiso | ||
* @since 1.0 | ||
*/ | ||
abstract class Spek(val spec: Dsl.() -> Unit) | ||
abstract class Spek(val spec: Spec.() -> Unit) { | ||
companion object { | ||
fun wrap(spec: Spec.() -> Unit) = object: Spek(spec) {} | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
spek-api/src/main/kotlin/org/jetbrains/spek/api/dsl/ActionBody.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,9 @@ | ||
package org.jetbrains.spek.api.dsl | ||
|
||
import org.jetbrains.spek.meta.SpekDsl | ||
|
||
/** | ||
* @author Ranie Jade Ramiso | ||
*/ | ||
@SpekDsl | ||
interface ActionBody: TestContainer |
14 changes: 0 additions & 14 deletions
14
spek-api/src/main/kotlin/org/jetbrains/spek/api/dsl/Dsl.kt
This file was deleted.
Oops, something went wrong.
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
13 changes: 13 additions & 0 deletions
13
spek-api/src/main/kotlin/org/jetbrains/spek/api/dsl/Spec.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,13 @@ | ||
package org.jetbrains.spek.api.dsl | ||
|
||
import org.jetbrains.spek.api.lifecycle.LifecycleListener | ||
import org.jetbrains.spek.meta.Experimental | ||
|
||
/** | ||
* @author Ranie Jade Ramiso | ||
* @since 1.1 | ||
*/ | ||
@Experimental | ||
interface Spec: SpecBody { | ||
fun registerListener(listener: LifecycleListener) | ||
} |
19 changes: 19 additions & 0 deletions
19
spek-api/src/main/kotlin/org/jetbrains/spek/api/dsl/SpecBody.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,19 @@ | ||
package org.jetbrains.spek.api.dsl | ||
|
||
import org.jetbrains.spek.api.lifecycle.CachingMode | ||
import org.jetbrains.spek.api.lifecycle.LifecycleAware | ||
import org.jetbrains.spek.meta.SpekDsl | ||
|
||
/** | ||
* @author Ranie Jade Ramiso | ||
* @since 1.0 | ||
*/ | ||
@SpekDsl | ||
interface SpecBody: TestContainer { | ||
fun group(description: String, pending: Pending = Pending.No, body: SpecBody.() -> Unit) | ||
fun action(description: String, pending: Pending = Pending.No, body: ActionBody.() -> Unit) | ||
fun <T> memoized(mode: CachingMode = CachingMode.TEST, factory: () -> T): LifecycleAware<T> | ||
|
||
fun beforeEachTest(callback: () -> Unit) | ||
fun afterEachTest(callback: () -> Unit) | ||
} |
57 changes: 22 additions & 35 deletions
57
spek-api/src/main/kotlin/org/jetbrains/spek/api/dsl/Standard.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 |
---|---|---|
@@ -1,114 +1,101 @@ | ||
package org.jetbrains.spek.api.dsl | ||
|
||
import org.jetbrains.spek.api.SubjectSpek | ||
import kotlin.reflect.KClass | ||
|
||
/** | ||
* Creates a [group][Dsl.group]. | ||
* Creates a [group][SpecBody.group]. | ||
* | ||
* @author Ranie Jade Ramiso | ||
* @since 1.0 | ||
*/ | ||
fun Dsl.describe(description: String, body: Dsl.() -> Unit) { | ||
fun SpecBody.describe(description: String, body: SpecBody.() -> Unit) { | ||
group("describe $description", body = body) | ||
} | ||
|
||
/** | ||
* Creates a [group][Dsl.group]. | ||
* Creates a [group][SpecBody.group]. | ||
* | ||
* @author Ranie Jade Ramiso | ||
* @since 1.0 | ||
*/ | ||
fun Dsl.context(description: String, body: Dsl.() -> Unit) { | ||
fun SpecBody.context(description: String, body: SpecBody.() -> Unit) { | ||
group("context $description", body = body) | ||
} | ||
|
||
/** | ||
* Creates a [group][Dsl.group]. | ||
* Creates a [group][SpecBody.group]. | ||
* | ||
* @author Ranie Jade Ramiso | ||
* @since 1.0 | ||
*/ | ||
fun Dsl.given(description: String, body: Dsl.() -> Unit) { | ||
fun SpecBody.given(description: String, body: SpecBody.() -> Unit) { | ||
group("given $description", body = body) | ||
} | ||
|
||
/** | ||
* Creates a [group][Dsl.group]. | ||
* Creates a [group][SpecBody.group]. | ||
* | ||
* @author Ranie Jade Ramiso | ||
* @since 1.0 | ||
*/ | ||
fun Dsl.on(description: String, body: Dsl.() -> Unit) { | ||
group("on $description", lazy = true, body = body) | ||
fun SpecBody.on(description: String, body: ActionBody.() -> Unit) { | ||
action("on $description", body = body) | ||
} | ||
|
||
/** | ||
* Creates a [test][Dsl.test]. | ||
* Creates a [test][SpecBody.test]. | ||
* | ||
* @author Ranie Jade Ramiso | ||
* @since 1.0 | ||
*/ | ||
fun Dsl.it(description: String, body: () -> Unit) { | ||
fun TestContainer.it(description: String, body: TestBody.() -> Unit) { | ||
test("it $description", body = body) | ||
} | ||
|
||
/** | ||
* Creates a [group][Dsl.group]. | ||
* Creates a [group][SpecBody.group]. | ||
* | ||
* @author Ranie Jade Ramiso | ||
* @since 1.0 | ||
*/ | ||
fun Dsl.xdescribe(description: String, reason: String? = null, body: Dsl.() -> Unit) { | ||
fun SpecBody.xdescribe(description: String, reason: String? = null, body: SpecBody.() -> Unit) { | ||
group("describe $description", Pending.Yes(reason), body = body) | ||
} | ||
|
||
/** | ||
* Creates a [group][Dsl.group]. | ||
* Creates a [group][SpecBody.group]. | ||
* | ||
* @author Ranie Jade Ramiso | ||
* @since 1.0 | ||
*/ | ||
fun Dsl.xcontext(description: String, reason: String? = null, body: Dsl.() -> Unit) { | ||
fun SpecBody.xcontext(description: String, reason: String? = null, body: SpecBody.() -> Unit) { | ||
group("context $description", Pending.Yes(reason), body = body) | ||
} | ||
|
||
/** | ||
* Creates a [group][Dsl.group]. | ||
* Creates a [group][SpecBody.group]. | ||
* | ||
* @author Ranie Jade Ramiso | ||
* @since 1.0 | ||
*/ | ||
fun Dsl.xgiven(description: String, reason: String? = null, body: Dsl.() -> Unit) { | ||
fun SpecBody.xgiven(description: String, reason: String? = null, body: SpecBody.() -> Unit) { | ||
group("given $description", Pending.Yes(reason), body = body) | ||
} | ||
|
||
/** | ||
* Creates a pending [group][Dsl.group]. | ||
* Creates a pending [group][SpecBody.group]. | ||
* | ||
* @author Ranie Jade Ramiso | ||
* @since 1.0 | ||
*/ | ||
fun Dsl.xon(description: String, reason: String? = null, body: Dsl.() -> Unit = {}) { | ||
group("on $description", Pending.Yes(reason), lazy = true, body = body) | ||
fun SpecBody.xon(description: String, reason: String? = null, body: ActionBody.() -> Unit = {}) { | ||
action("on $description", Pending.Yes(reason), body = body) | ||
} | ||
|
||
/** | ||
* Creates a pending [test][Dsl.test]. | ||
* Creates a pending [test][SpecBody.test]. | ||
* | ||
* @author Ranie Jade Ramiso | ||
* @since 1.0 | ||
*/ | ||
fun Dsl.xit(description: String, reason: String? = null, body: () -> Unit = {}) { | ||
fun TestContainer.xit(description: String, reason: String? = null, body: TestBody.() -> Unit = {}) { | ||
test("it $description", Pending.Yes(reason), body) | ||
} | ||
|
||
/** | ||
* Alias for [SubjectDsl.includeSubjectSpec]. | ||
* | ||
* @author Ranie Jade Ramiso | ||
* @since 1.0 | ||
*/ | ||
fun <T, K: SubjectSpek<T>> SubjectDsl<*>.itBehavesLike(spec: KClass<K>) { | ||
includeSubjectSpec(spec) | ||
} |
19 changes: 0 additions & 19 deletions
19
spek-api/src/main/kotlin/org/jetbrains/spek/api/dsl/SubjectDsl.kt
This file was deleted.
Oops, something went wrong.
9 changes: 9 additions & 0 deletions
9
spek-api/src/main/kotlin/org/jetbrains/spek/api/dsl/TestBody.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,9 @@ | ||
package org.jetbrains.spek.api.dsl | ||
|
||
import org.jetbrains.spek.meta.SpekDsl | ||
|
||
/** | ||
* @author Ranie Jade Ramiso | ||
*/ | ||
@SpekDsl | ||
interface TestBody |
11 changes: 11 additions & 0 deletions
11
spek-api/src/main/kotlin/org/jetbrains/spek/api/dsl/TestContainer.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,11 @@ | ||
package org.jetbrains.spek.api.dsl | ||
|
||
import org.jetbrains.spek.meta.SpekDsl | ||
|
||
/** | ||
* @author Ranie Jade Ramiso | ||
*/ | ||
@SpekDsl | ||
interface TestContainer { | ||
fun test(description: String, pending: Pending = Pending.No, body: TestBody.() -> Unit) | ||
} |
6 changes: 6 additions & 0 deletions
6
spek-api/src/main/kotlin/org/jetbrains/spek/api/lifecycle/ActionScope.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,6 @@ | ||
package org.jetbrains.spek.api.lifecycle | ||
|
||
/** | ||
* @author Ranie Jade Ramiso | ||
*/ | ||
interface ActionScope: GroupScope |
7 changes: 3 additions & 4 deletions
7
...etbrains/spek/api/memoized/CachingMode.kt → ...tbrains/spek/api/lifecycle/CachingMode.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
6 changes: 3 additions & 3 deletions
6
...brains/spek/extension/ExtensionContext.kt → ...etbrains/spek/api/lifecycle/GroupScope.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 |
---|---|---|
@@ -1,10 +1,10 @@ | ||
package org.jetbrains.spek.extension | ||
package org.jetbrains.spek.api.lifecycle | ||
|
||
import org.jetbrains.spek.meta.Experimental | ||
|
||
/** | ||
* @author Ranie Jade Ramiso | ||
* @since 1.1 | ||
*/ | ||
@Experimental | ||
interface ExtensionContext { | ||
} | ||
interface GroupScope: Scope |
14 changes: 14 additions & 0 deletions
14
spek-api/src/main/kotlin/org/jetbrains/spek/api/lifecycle/InstanceFactory.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,14 @@ | ||
package org.jetbrains.spek.api.lifecycle | ||
|
||
import org.jetbrains.spek.api.Spek | ||
import org.jetbrains.spek.meta.Experimental | ||
import kotlin.reflect.KClass | ||
|
||
/** | ||
* @author Ranie Jade Ramiso | ||
* @since 1.1 | ||
*/ | ||
@Experimental | ||
interface InstanceFactory { | ||
fun <T: Spek> create(spek: KClass<T>): T | ||
} |
Oops, something went wrong.