Sign in

    moonspec

    BDD test framework for MoonBit with Gherkin and Cucumber Expressions

    bdd
    cucumber
    gherkin
    testing
    moonbit
    Download zip
    Author
    Version
    0.2.0
    License
    Apache-2.0
    Last updated
    8 months ago
    Downloads
    7K

    #moonspec

    BDD test framework for MoonBit with Gherkin and Cucumber Expressions.

    #Installation

    moon add moonrockz/moonspec

    #Quick Start

    Define a World struct, implement step definitions, and run:

    struct CalcWorld {
    mut result : Int
    } derive(Default)

    impl @moonspec.World for CalcWorld with register_steps(self, s) {
    s.given("a calculator", fn(_args) { self.result = 0 })
    s.when("I add {int} and {int}", fn(args) {
    match (args[0], args[1]) {
    (@moonspec.StepArg::IntArg(a), @moonspec.StepArg::IntArg(b)) => self.result = a + b
    _ => ()
    }
    })
    s.then("the result should be {int}", fn(args) raise {
    match args[0] {
    @moonspec.StepArg::IntArg(expected) => assert_eq(self.result, expected)
    _ => ()
    }
    })
    }

    async test "calculator" {
    let feature =
    #|Feature: Calculator
    #|
    #| Scenario: Addition
    #| Given a calculator
    #| When I add 2 and 3
    #| Then the result should be 5
    @moonspec.run_or_fail(
    CalcWorld::default,
    [@moonspec.FeatureSource::Text("test://calculator", feature)],
    )
    |> ignore
    }

    Each scenario gets a fresh World instance via derive(Default) for state isolation.

    #Features

    • World trait -- per-scenario state isolation following cucumber-rs patterns
    • StepLibrary trait -- composable, reusable step definition groups
    • StepDef type -- first-class step definitions you can inspect, test, and pass around
    • Structured errors -- MoonspecError hierarchy with run_or_fail throwing variant
    • Undefined step diagnostics -- copy-paste snippets and "did you mean?" suggestions
    • Lifecycle hooks -- before_scenario, after_scenario, before_step, after_step
    • Gherkin parsing -- Feature, Scenario, Scenario Outline, Background, Rules, Data Tables, Doc Strings
    • Cucumber Expressions -- type-safe step matching with {int}, {float}, {string}, {word}
    • Tag filtering -- boolean tag expressions (@smoke and not @slow)
    • Scenario Outline expansion -- parameterized scenarios from Examples tables
    • Background steps -- shared Given setup across scenarios
    • Async/parallel execution -- concurrent feature processing with bounded concurrency
    • Codegen -- generate _test.mbt runner tests from .feature files
    • Formatters -- Pretty (console), Cucumber Messages (NDJSON), JUnit XML (CI)

    #Packages

    PackageDescription
    moonrockz/moonspecTop-level facade -- World, Hooks, StepArg, run, run_with_hooks
    moonrockz/moonspec/coreWorld and Hooks traits, StepRegistry, StepArg types
    moonrockz/moonspec/runnerFeature/scenario executor with tag filtering and parallel support
    moonrockz/moonspec/formatFormatter trait + Pretty, Messages, JUnit implementations
    moonrockz/moonspec/codegenGenerate test files from Gherkin features

    #Documentation

    Full documentation with CLI reference, architecture, and examples: github.com/moonrockz/moonspec

    #License

    Apache-2.0

    FeatureResult

    Result of executing a feature.

    FeatureSource

    Input source for a feature to be loaded into the cache.

    Hooks

    moonspec — BDD test framework for MoonBit.

    Re-exports core types and runner functions so users import just moonrockz/moonspec and use @moonspec.World, @moonspec.run, etc.

    MoonspecError

    moonspec — BDD test framework for MoonBit.

    Re-exports core types and runner functions so users import just moonrockz/moonspec and use @moonspec.World, @moonspec.run, etc.

    RunResult

    Complete result of a test run.

    RunSummary

    Summary of an entire run.

    ScenarioInfo

    moonspec — BDD test framework for MoonBit.

    Re-exports core types and runner functions so users import just moonrockz/moonspec and use @moonspec.World, @moonspec.run, etc.

    ScenarioResult

    Result of executing a scenario.

    ScenarioStatus

    Aggregate status of a scenario.

    StepArg

    moonspec — BDD test framework for MoonBit.

    Re-exports core types and runner functions so users import just moonrockz/moonspec and use @moonspec.World, @moonspec.run, etc.

    StepDef

    moonspec — BDD test framework for MoonBit.

    Re-exports core types and runner functions so users import just moonrockz/moonspec and use @moonspec.World, @moonspec.run, etc.

    StepInfo

    moonspec — BDD test framework for MoonBit.

    Re-exports core types and runner functions so users import just moonrockz/moonspec and use @moonspec.World, @moonspec.run, etc.

    StepKeyword

    moonspec — BDD test framework for MoonBit.

    Re-exports core types and runner functions so users import just moonrockz/moonspec and use @moonspec.World, @moonspec.run, etc.

    StepLibrary

    moonspec — BDD test framework for MoonBit.

    Re-exports core types and runner functions so users import just moonrockz/moonspec and use @moonspec.World, @moonspec.run, etc.

    StepMatchResult

    moonspec — BDD test framework for MoonBit.

    Re-exports core types and runner functions so users import just moonrockz/moonspec and use @moonspec.World, @moonspec.run, etc.

    StepRegistry

    moonspec — BDD test framework for MoonBit.

    Re-exports core types and runner functions so users import just moonrockz/moonspec and use @moonspec.World, @moonspec.run, etc.

    StepResult

    Result of executing a single step.

    StepSource

    moonspec — BDD test framework for MoonBit.

    Re-exports core types and runner functions so users import just moonrockz/moonspec and use @moonspec.World, @moonspec.run, etc.

    StepStatus

    Status of a single step execution.

    World

    moonspec — BDD test framework for MoonBit.

    Re-exports core types and runner functions so users import just moonrockz/moonspec and use @moonspec.World, @moonspec.run, etc.

    run

    async fn[W :
    World
    ] run(factory : () -> W, features : Array[
    FeatureSource
    ], tag_expr? : String, scenario_name? : String, parallel? : Int) ->
    RunResult

    Run all features and collect results.

    A fresh world is created per scenario via factory() for isolation. When parallel is greater than 0, pickles are executed concurrently using @async.all() with bounded concurrency. Otherwise, pickles run sequentially.

    run_or_fail

    async fn[W :
    World
    ] run_or_fail(factory : () -> W, features : Array[
    FeatureSource
    ], tag_expr? : String, scenario_name? : String, parallel? : Int) ->
    RunResult

    Run all features, raising MoonspecError on any failure.

    This is the ergonomic test API. Use in generated tests and manual tests where you want structured error output instead of manual result inspection.

    run_with_hooks

    async fn[W :
    World
    +
    Hooks
    ] run_with_hooks(factory : () -> W, features : Array[
    FeatureSource
    ], tag_expr? : String, scenario_name? : String, parallel? : Int) ->
    RunResult

    Run all features with lifecycle hooks and collect results.

    Like run, but calls before/after_scenario and before/after_step hooks on the world. The world must implement both World and Hooks traits.

    Source Files