All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.cucumber.scala.ScalaHookDefinition.scala Maven / Gradle / Ivy

There is a newer version: 8.25.1
Show newest version
package io.cucumber.scala

import io.cucumber.core.backend.{HookDefinition, ScenarioScoped, TestCaseState}

trait ScalaHookDefinition extends HookDefinition with AbstractGlueDefinition {

  val hookDetails: ScalaHookDetails

  override val location: StackTraceElement = new Exception().getStackTrace()(3)

  override def execute(state: TestCaseState): Unit = {
    executeAsCucumber(hookDetails.body.apply(new Scenario(state)))
  }

  override def getTagExpression: String = hookDetails.tagExpression

  override def getOrder: Int = hookDetails.order

}

object ScalaHookDefinition {

  def apply(
      scalaHookDetails: ScalaHookDetails,
      scenarioScoped: Boolean
  ): ScalaHookDefinition = {
    if (scenarioScoped) {
      new ScalaScenarioScopedHookDefinition(scalaHookDetails)
    } else {
      new ScalaGlobalHookDefinition(scalaHookDetails)
    }
  }

}

class ScalaScenarioScopedHookDefinition(
    override val hookDetails: ScalaHookDetails
) extends ScalaHookDefinition
    with ScenarioScoped {}

class ScalaGlobalHookDefinition(override val hookDetails: ScalaHookDetails)
    extends ScalaHookDefinition {}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy