How to use TagsExcludedSpecInterceptor class of io.kotest.engine.spec.interceptor package

Best Kotest code snippet using io.kotest.engine.spec.interceptor.TagsExcludedSpecInterceptor

SpecExecutor.kt

Source:SpecExecutor.kt Github

copy

Full Screen

...28import io.kotest.engine.spec.interceptor.SpecRefExtensionInterceptor29import io.kotest.engine.spec.interceptor.SpecRefInterceptor30import io.kotest.engine.spec.interceptor.SpecStartedInterceptor31import io.kotest.engine.spec.interceptor.SystemPropertySpecFilterInterceptor32import io.kotest.engine.spec.interceptor.TagsExcludedSpecInterceptor33import io.kotest.mpp.Logger34import io.kotest.mpp.bestName35import kotlin.reflect.KClass36/**37 * Executes a single [SpecRef].38 *39 * Uses a [TestEngineListener] to notify of events in the spec lifecycle.40 *41 * The spec executor has two levels of interceptors:42 * [io.kotest.engine.spec.interceptor.SpecRefInterceptor] are executed before the spec is created.43 * [io.kotest.engine.spec.interceptor.SpecInterceptor] are executed after the spec is created.44 *45 */46@ExperimentalKotest47class SpecExecutor(48 private val defaultCoroutineDispatcherFactory: CoroutineDispatcherFactory,49 private val context: EngineContext,50) {51 private val logger = Logger(SpecExecutorDelegate::class)52 private val extensions = SpecExtensions(context.configuration.registry)53 private val listener = context.listener54 suspend fun execute(ref: SpecRef) {55 logger.log { Pair(ref.kclass.bestName(), "Received $ref") }56 referenceInterceptors(ref)57 }58 suspend fun execute(kclass: KClass<out Spec>) {59 execute(SpecRef.Reference(kclass))60 }61 private suspend fun referenceInterceptors(ref: SpecRef) {62 val interceptors = listOfNotNull(63 if (platform == Platform.JVM) EnabledIfSpecInterceptor(listener, context.configuration.registry) else null,64 IgnoredSpecInterceptor(listener, context.configuration.registry),65 SpecFilterInterceptor(listener, context.configuration.registry),66 SystemPropertySpecFilterInterceptor(listener, context.configuration.registry),67 TagsExcludedSpecInterceptor(listener, context.configuration),68 if (platform == Platform.JVM) RequiresTagSpecInterceptor(listener, context.configuration, context.configuration.registry) else null,69 SpecRefExtensionInterceptor(context.configuration.registry),70 SpecStartedInterceptor(listener),71 SpecFinishedInterceptor(listener),72 if (platform == Platform.JVM) ApplyExtensionsInterceptor(context.configuration.registry) else null,73 PrepareSpecInterceptor(context.configuration.registry),74 FinalizeSpecInterceptor(context.configuration.registry),75 )76 val innerExecute: suspend (SpecRef) -> Result<Map<TestCase, TestResult>> = {77 createInstance(ref).flatMap { specInterceptors(it) }78 }79 logger.log { Pair(ref.kclass.bestName(), "Executing ${interceptors.size} reference interceptors") }80 interceptors.foldRight(innerExecute) { ext: SpecRefInterceptor, fn: suspend (SpecRef) -> Result<Map<TestCase, TestResult>> ->81 { ref -> ext.intercept(ref, fn) }...

Full Screen

Full Screen

TagsExcludedDiscoveryExtensionTest.kt

Source:TagsExcludedDiscoveryExtensionTest.kt Github

copy

Full Screen

...8import io.kotest.core.spec.style.ExpectSpec9import io.kotest.core.spec.style.FunSpec10import io.kotest.engine.extensions.SpecifiedTagsTagExtension11import io.kotest.engine.listener.NoopTestEngineListener12import io.kotest.engine.spec.interceptor.TagsExcludedSpecInterceptor13import io.kotest.matchers.booleans.shouldBeTrue14@ExperimentalKotest15class TagsExcludedDiscoveryExtensionTest : FunSpec() {16 init {17 test("TagsExcludedSpecInterceptor should support include & exclude") {18 val tags = TagExpression.Empty.include(NamedTag("SpecIncluded")).exclude(NamedTag("SpecExcluded"))19 val conf = ProjectConfiguration()20 conf.registry.add(SpecifiedTagsTagExtension(tags))21 // will be excluded explicitly22 TagsExcludedSpecInterceptor(NoopTestEngineListener, conf)23 .intercept(SpecRef.Reference(ExcludedSpec::class)) { error("foo") }24 // will be included as includes are ignored at the class level25 var executed = false26 TagsExcludedSpecInterceptor(NoopTestEngineListener, conf)27 .intercept(SpecRef.Reference(IncludedSpec::class)) {28 executed = true29 Result.success(emptyMap())30 }31 executed.shouldBeTrue()32 // will be included as we can must check the spec itself later to see if the test themselves have the include or exclude33 executed = false34 TagsExcludedSpecInterceptor(NoopTestEngineListener, conf)35 .intercept(SpecRef.Reference(UntaggedSpec::class)) {36 executed = true37 Result.success(emptyMap())38 }39 executed.shouldBeTrue()40 }41 test("TagsExcludedSpecInterceptor should ignore include only") {42 val tags = TagExpression.Empty.include(NamedTag("SpecIncluded"))43 val conf = ProjectConfiguration()44 conf.registry.add(SpecifiedTagsTagExtension(tags))45 var executed = false46 TagsExcludedSpecInterceptor(NoopTestEngineListener, conf)47 .intercept(SpecRef.Reference(ExcludedSpec::class)) {48 executed = true49 Result.success(emptyMap())50 }51 executed.shouldBeTrue()52 executed = false53 TagsExcludedSpecInterceptor(NoopTestEngineListener, conf)54 .intercept(SpecRef.Reference(IncludedSpec::class)) {55 executed = true56 Result.success(emptyMap())57 }58 executed.shouldBeTrue()59 executed = false60 TagsExcludedSpecInterceptor(NoopTestEngineListener, conf)61 .intercept(SpecRef.Reference(UntaggedSpec::class)) {62 executed = true63 Result.success(emptyMap())64 }65 executed.shouldBeTrue()66 }67 test("TagsExcludedSpecInterceptor should support exclude only") {68 val tags = TagExpression.Empty.exclude(NamedTag("SpecExcluded"))69 val conf = ProjectConfiguration()70 conf.registry.add(SpecifiedTagsTagExtension(tags))71 TagsExcludedSpecInterceptor(NoopTestEngineListener, conf)72 .intercept(SpecRef.Reference(ExcludedSpec::class)) {73 error("foo")74 }75 var executed = false76 TagsExcludedSpecInterceptor(NoopTestEngineListener, conf)77 .intercept(SpecRef.Reference(IncludedSpec::class)) {78 executed = true79 Result.success(emptyMap())80 }81 executed.shouldBeTrue()82 executed = false83 TagsExcludedSpecInterceptor(NoopTestEngineListener, conf)84 .intercept(SpecRef.Reference(UntaggedSpec::class)) {85 executed = true86 Result.success(emptyMap())87 }88 executed.shouldBeTrue()89 }90 }91}92@io.kotest.core.annotation.Tags("SpecExcluded")93private class ExcludedSpec : ExpectSpec()94@io.kotest.core.annotation.Tags("SpecIncluded")95private class IncludedSpec : BehaviorSpec()96private class UntaggedSpec : FunSpec()...

Full Screen

Full Screen

TagsExcludedDiscoveryExtension.kt

Source:TagsExcludedDiscoveryExtension.kt Github

copy

Full Screen

...13import io.kotest.engine.tags.runtimeTags14/**15 * Filters any [Spec] that can be eagerly excluded based on the @[TagExpression] annotation at the class level.16 */17class TagsExcludedSpecInterceptor(18 private val listener: TestEngineListener,19 private val conf: ProjectConfiguration,20) : SpecRefInterceptor {21 private val extensions = SpecExtensions(conf.registry)22 override suspend fun intercept(23 ref: SpecRef,24 fn: suspend (SpecRef) -> Result<Map<TestCase, TestResult>>25 ): Result<Map<TestCase, TestResult>> {26 val potentiallyActive = conf.runtimeTags().parse().isPotentiallyActive(ref.kclass)27 return if (potentiallyActive) {28 fn(ref)29 } else {30 runCatching { listener.specIgnored(ref.kclass, null) }31 .flatMap { extensions.ignored(ref.kclass, "Skipped by tags") }...

Full Screen

Full Screen

TagsExcludedSpecInterceptor

Using AI Code Generation

copy

Full Screen

1class TagsExcludedSpecInterceptor(private val excludedTags: Set<Tag>) : SpecExecutionInterceptor {2 override suspend fun intercept(spec: Spec, execute: suspend (Spec) -> Unit) {3 if (spec is Taggable) {4 if (spec.tags().any { excludedTags.contains(it) }) {5 }6 }7 execute(spec)8 }9}10class TagsExcludedSpecInterceptor(private val excludedTags: Set<Tag>) : SpecExecutionInterceptor {11 override suspend fun intercept(spec: Spec, execute: suspend (Spec) -> Unit) {12 if (spec is Taggable) {13 if (spec.tags().any { excludedTags.contains(it) }) {14 }15 }16 execute(spec)17 }18}19class TagsExcludedSpecInterceptor(private val excludedTags: Set<Tag>) : SpecExecutionInterceptor {20 override suspend fun intercept(spec: Spec, execute: suspend (Spec) -> Unit) {21 if (spec is Taggable) {22 if (spec.tags().any { excludedTags.contains(it) }) {23 }24 }25 execute(spec)26 }27}28class TagsExcludedSpecInterceptor(private val excludedTags: Set<Tag>) : SpecExecutionInterceptor {29 override suspend fun intercept(spec: Spec, execute: suspend (Spec) -> Unit) {30 if (spec is Taggable) {31 if (spec.tags().any { excludedTags.contains(it) }) {32 }33 }34 execute(spec)35 }36}37class TagsExcludedSpecInterceptor(private val excludedTags: Set<Tag>) : SpecExecutionInterceptor {38 override suspend fun intercept(spec: Spec, execute: suspend (Spec) -> Unit) {39 if (spec is Taggable

Full Screen

Full Screen

TagsExcludedSpecInterceptor

Using AI Code Generation

copy

Full Screen

1TagsExcludedSpecInterceptor("slow", "db")2TagsExcludedSpecInterceptor("slow", "db") { spec: Spec, tags: Set<Tag> -> tags.contains(Tag("slow")) }3TagsExcludedSpecInterceptor("slow", "db") { spec: Spec -> spec is MySpec }4TagsExcludedSpecInterceptor("slow", "db") { spec: Spec -> spec is MySpec || spec is MyOtherSpec }5TagsExcludedSpecInterceptor("slow", "db") { spec: Spec, tags: Set<Tag> -> tags.contains(Tag("slow")) || tags.contains(Tag("db")) }6TagsExcludedSpecInterceptor("slow", "db") { spec: Spec -> spec is MySpec || spec is MyOtherSpec } { spec: Spec, tags: Set<Tag> -> tags.contains(Tag("slow")) || tags.contains(Tag("db")) }7TagsExcludedSpecInterceptor("slow", "db") { spec: Spec, tags: Set<Tag> -> tags.contains(Tag("slow")) || tags.contains(Tag("db")) } { spec: Spec -> spec is MySpec || spec is MyOtherSpec }8TagsExcludedSpecInterceptor("

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Kotest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful