spek icon indicating copy to clipboard operation
spek copied to clipboard

Support Focused as an extension

Open raniejade opened this issue 6 years ago • 4 comments

UNDER CONSTRUCTION (NOT FINAL)

Motivation

Earlier versions of Spek had support for focused versions of the built-in scopes (prefixed with an f), when used Spek will only execute those scopes. This was subsequently removed in later versions because we see it as only a temporary solution for the lack of proper tooling. This still stands but we can see it to be useful in specific circumstances. We don't want it to be part of core Spek so it will be implemented as an extension.

Proposal

For this to work we need to introduce support for filtering the test tree and introduce support for tagging.

Tagging

This will allow developers to tag their scopes. One use-case is tagging a scope for a particular environment (windows, linux, etc ...).

describe("windows only", tags = arrayOf("windows")) {
    ...
} 

SpecPostProcessor

This will be invoked for each Spek and implementations can mutate the test tree.

interface SpecPostProcessor {
    fun postProcessSpec(root: GroupScope)
}

Scope classes will also be updated to include removeFromHierarchy().

Focused

Implementing it requires doing two passes. First pass checks if there are any scopes with the tag focused and second pass does the actual mutation of the test tree.

class FocusedExtension: SpecPostProcessor {
    override fun postProcessSpec(root: GroupScope) {
        if (doFirstPass(root)) {
            doSecondPass(root)
        }
    }

    private fun doFirstPass(root: GroupScope): Boolean { ... }
    private fun doSecondPass(root: GroupScope) { ... }
}

raniejade avatar Aug 17 '17 10:08 raniejade

Would be great if IntelliJ plugin would reuse exact same API to run particular test/group!

artem-zinnatullin avatar Aug 17 '17 18:08 artem-zinnatullin

@artem-zinnatullin that's an interesting idea, I'll consider it!

raniejade avatar Aug 18 '17 00:08 raniejade

Would be great if IntelliJ plugin would reuse exact same API to run particular test/group!

Just realised it has some performance implications. It implies that Spek should discover everything first, currently filtering is done while discovering the scopes.

raniejade avatar Aug 18 '17 07:08 raniejade

KotlinTest seems to do this with system properties: https://github.com/kotlintest/kotlintest/blob/master/doc/reference.md#focus

It could currently be done by making extra extension functions for groups that just check those system properties against the tags passed...? Of course, having this integrated deeper in Spek might be more efficient...

dave08 avatar Jun 11 '18 11:06 dave08