Sign in

    moonrockz/moonspec/core does not have a README file

    Hooks

    pub(open) trait Hooks {
    before_scenario(Self, ScenarioInfo) -> Unit raise = _
    after_scenario(Self, ScenarioInfo, String?) -> Unit raise = _
    before_step(Self, StepInfo) -> Unit raise = _
    after_step(Self, StepInfo, String?) -> Unit raise = _
    }

    Lifecycle hooks for scenario execution.

    All methods have default no-op implementations. Users optionally implement this on their world struct for setup/teardown logic.

    The String? result parameter is None for success, Some(message) for failure.

    StepLibrary

    pub(open) trait StepLibrary {
    steps(Self) -> ArrayView[StepDef]
    }

    A composable group of step definitions.

    Implement this on structs that provide reusable step definitions. Libraries return an immutable view of their steps via ArrayView.

    World

    pub(open) trait World {
    register_steps(Self, StepRegistry) -> Unit
    }

    Step registration trait. Users implement this on their world struct.

    Called once per scenario with a fresh Default-constructed instance. Closures registered via StepRegistry capture self, sharing world state between steps within the same scenario. Since MoonBit structs are reference types, mutations through closures are visible to all step handlers.

    Example:
    struct MyWorld { mut count : Int } derive(Default) impl @moonspec.World for MyWorld with register_steps(self, s) { s.given("a count of {int}", fn(args) { match args[0] { @moonspec.IntArg(n) => self.count = n | _ => () } }) }

    MoonspecError

    pub suberror MoonspecError {
    UndefinedStep(String, String, String, Array[String])
    PendingStep(String, String, String)
    StepFailed(String, String, String)
    ScenarioFailed(String, String, Array[MoonspecError])
    RunFailed(String, Array[MoonspecError])
    }

    Structured error hierarchy for moonspec.

    Step-level errors aggregate into ScenarioFailed, which aggregates into RunFailed. This enables rich diagnostics and the run_or_fail! API.

    CompiledStep

    type CompiledStep

    Internal: a compiled step entry pairing a StepDef with its parsed expression.

    ScenarioInfo

    pub(all) struct ScenarioInfo {
    feature_name : String
    scenario_name : String
    tags : Array[String]
    }

    Information about a scenario being executed.
    impl Eq for ScenarioInfo

    StepArg

    pub(all) enum StepArg {
    IntArg(Int)
    FloatArg(Double)
    StringArg(String)
    WordArg(String)
    CustomArg(String)
    }

    A typed step argument extracted from step text via Cucumber Expressions.
    impl Eq for StepArg
    impl Show for StepArg

    StepArg::from_param

    Convert a cucumber-expressions Param to a typed StepArg.

    StepDef

    pub(all) struct StepDef {
    keyword : StepKeyword
    pattern : String
    handler : StepHandler
    source : StepSource?
    }

    A first-class step definition: keyword, pattern, handler, and optional source.

    StepDef::given

    fn StepDef::given(pattern : String, handler : (Array[StepArg]) -> Unit raise, source? : StepSource) -> StepDef

    StepDef::step

    fn StepDef::step(pattern : String, handler : (Array[StepArg]) -> Unit raise, source? : StepSource) -> StepDef

    StepDef::then

    fn StepDef::then(pattern : String, handler : (Array[StepArg]) -> Unit raise, source? : StepSource) -> StepDef

    StepDef::when

    fn StepDef::when(pattern : String, handler : (Array[StepArg]) -> Unit raise, source? : StepSource) -> StepDef

    StepHandler

    pub type StepHandler (Array[StepArg]) -> Unit raise

    A step handler function that receives extracted arguments.

    StepHandler::inner

    #deprecated("Use `struct T(A)` to declare a newtype and use `.0` access the underlying type instead.")
    fn StepHandler::inner(self : StepHandler) -> ((Array[StepArg]) -> Unit raise)
    Convert newtype to its underlying type, automatically derived.

    StepInfo

    pub(all) struct StepInfo {
    keyword : String
    text : String
    }

    Information about a step being executed.
    impl Eq for StepInfo
    impl Show for StepInfo

    StepKeyword

    pub(all) enum StepKeyword {
    Given
    When
    Then
    Step
    }

    Keyword classification for a step definition.
    impl Eq for StepKeyword
    impl Show for StepKeyword

    StepMatchResult

    pub(all) enum StepMatchResult {
    Matched(StepDef, Array[StepArg])
    Undefined(String, String, String, Array[String])
    }

    Result of matching step text against the registry.

    StepRegistry

    pub(all) struct StepRegistry {
    // private fields
    }

    Registry of step definitions keyed by Cucumber Expression patterns.

    StepRegistry::find_match

    fn StepRegistry::find_match(self : StepRegistry, text : String, keyword? : String) -> StepMatchResult

    Find a matching step definition for the given step text. Returns Matched with StepDef + extracted args, or Undefined with diagnostics.

    StepRegistry::given

    fn StepRegistry::given(self : StepRegistry, pattern : String, handler : (Array[StepArg]) -> Unit raise) -> Unit

    Register a Given step.

    StepRegistry::len

    fn StepRegistry::len(self : StepRegistry) -> Int

    Number of registered step definitions.

    StepRegistry::new

    Create an empty step registry with default parameter types.

    StepRegistry::register_def

    fn StepRegistry::register_def(self : StepRegistry, step_def : StepDef) -> Unit

    Register a StepDef directly.

    StepRegistry::step

    fn StepRegistry::step(self : StepRegistry, pattern : String, handler : (Array[StepArg]) -> Unit raise) -> Unit

    Register a step that matches any keyword.

    StepRegistry::then

    fn StepRegistry::then(self : StepRegistry, pattern : String, handler : (Array[StepArg]) -> Unit raise) -> Unit

    Register a Then step.

    StepRegistry::use_library

    fn[L : StepLibrary] StepRegistry::use_library(self : StepRegistry, library : L) -> Unit

    Compose a StepLibrary into this registry.

    StepRegistry::when

    fn StepRegistry::when(self : StepRegistry, pattern : String, handler : (Array[StepArg]) -> Unit raise) -> Unit

    Register a When step.

    StepSource

    pub(all) struct StepSource {
    uri : String?
    line : Int?
    }

    Optional source location for a step definition (populated by codegen).
    impl Eq for StepSource
    impl Show for StepSource

    StepSource::new

    fn StepSource::new(uri? : String, line? : Int) -> StepSource

    core_version

    fn core_version() -> String

    moonspec core — World, Steps, and Hooks traits.

    pending_step_error

    fn pending_step_error(step~ : String, keyword~ : String, message~ : String) -> Error

    Create a PendingStep error.

    run_failed_error

    fn run_failed_error(summary~ : String, errors~ : Array[MoonspecError]) -> Error

    Create a RunFailed error.

    scenario_failed_error

    fn scenario_failed_error(scenario~ : String, feature~ : String, errors~ : Array[MoonspecError]) -> MoonspecError

    Create a ScenarioFailed error.

    step_failed_error

    fn step_failed_error(step~ : String, keyword~ : String, message~ : String) -> Error

    Create a StepFailed error.

    undefined_step_error

    fn undefined_step_error(step~ : String, keyword~ : String, snippet~ : String, suggestions~ : Array[String]) -> Error

    Create an UndefinedStep error.