Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gherkin rule dsl missing #992

Open
sebastien-delaherche opened this issue Feb 16, 2022 · 0 comments
Open

Gherkin rule dsl missing #992

sebastien-delaherche opened this issue Feb 16, 2022 · 0 comments

Comments

@sebastien-delaherche
Copy link

sebastien-delaherche commented Feb 16, 2022

Hi guys,

First thank you for this framwork.

I think we miss some kind of Group between Feature and Scenario on Gherkin implementation.
In fact there is actually such definition on Gherkin specification: https://cucumber.io/docs/gherkin/reference/#rule

I would like to add it in the framework if it don't bother you?

I think it is just a matter of extension, BUT when I try to do it in my codebase, green arrow button on Android Studio has been replaced by "Do Nothing" text.

Can you help me on this issue?

Edit: Seems to be a duplicate of #873

@Synonym(SynonymType.GROUP, prefix = "Rule: ")
@Descriptions(Description(DescriptionLocation.VALUE_PARAMETER, 0))
fun FeatureBody.Rule(description: String, body: RuleBody.() -> Unit) =
    delegate.group("Rule: $description",
        defaultCachingMode = CachingMode.EACH_GROUP,
        preserveExecutionOrder = true,
        failFast = true) {
        body(RuleBody(this))
    }

@SpekDsl
class RuleBody(val delegate: GroupBody) : LifecycleAware by delegate {
    var defaultTimeout: Long
        get() = delegate.defaultTimeout
        set(value) {
            delegate.defaultTimeout = value
        }

    @Synonym(SynonymType.GROUP, prefix = "Scenario: ")
    @Descriptions(Description(DescriptionLocation.VALUE_PARAMETER, 0))
    fun Scenario(description: String, body: ScenarioBody.() -> Unit) {
        delegate.group("Scenario: $description",
            defaultCachingMode = CachingMode.SCOPE,
            preserveExecutionOrder = true,
            failFast = true) {
            body(ScenarioBody(this))
        }
    }

    @Synonym(SynonymType.GROUP, prefix = "Rule: ")
    @Descriptions(Description(DescriptionLocation.VALUE_PARAMETER, 0))
    fun Rule(description: String, body: RuleBody.() -> Unit) =
        delegate.group("Rule: $description",
            defaultCachingMode = CachingMode.EACH_GROUP,
            preserveExecutionOrder = true,
            failFast = true) {
            body(RuleBody(this))
        }

    fun beforeEachScenario(fixture: Fixture) = delegate.beforeEachGroup(fixture)
    fun afterEachScenario(fixture: Fixture) = delegate.afterEachGroup(fixture)
    fun beforeFeature(fixture: Fixture) = delegate.beforeGroup(fixture)
    fun afterFeature(fixture: Fixture) = delegate.afterGroup(fixture)

    @Deprecated("Use beforeEachScenario instead", ReplaceWith("beforeEachScenario(fixture)"))
    override fun beforeEachGroup(fixture: Fixture) = beforeEachScenario(fixture)

    @Deprecated("Use afterEachScenario instead", ReplaceWith("afterEachScenario(fixture)"))
    override fun afterEachGroup(fixture: Fixture) = afterEachScenario(fixture)

    @Deprecated("Use beforeFeature instead", ReplaceWith("beforeFeature(fixture)"))
    override fun beforeGroup(fixture: Fixture) = beforeFeature(fixture)

    @Deprecated("Use afterFeature instead", ReplaceWith("afterFeature(fixture)"))
    override fun afterGroup(fixture: Fixture) = afterFeature(fixture)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant