Sign in

    moonspec

    BDD test framework for MoonBit with Gherkin and Cucumber Expressions

    bdd
    cucumber
    gherkin
    testing
    moonbit
    Download zip
    Author
    Version
    0.3.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 configure(self, setup) {
    setup.given("a calculator", fn(_ctx) { self.result = 0 })
    setup.when("I add {int} and {int}", fn(ctx) {
    match (ctx[0], ctx[1]) {
    ({ value: @moonspec.StepValue::IntVal(a), .. }, { value: @moonspec.StepValue::IntVal(b), .. }) =>
    self.result = a + b
    _ => ()
    }
    })
    setup.then("the result should be {int}", fn(ctx) raise {
    match ctx[0] {
    { value: @moonspec.StepValue::IntVal(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.RunOptions::new([@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_test_case, after_test_case, before_test_step, after_test_step, before_test_run, after_test_run
    • Gherkin parsing -- Feature, Scenario, Scenario Outline, Background, Rules, Data Tables, Doc Strings
    • Cucumber Expressions -- type-safe step matching with 11 built-in types ({int}, {float}, {double}, {long}, {byte}, {short}, {bigdecimal}, {biginteger}, {string}, {word}) plus custom parameter types with transformers
    • 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, Setup, Ctx, RunOptions, run, run_or_fail
    moonrockz/moonspec/coreWorld trait, Setup facade, HookRegistry, StepRegistry, Ctx 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

    Attachable

    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.

    CaseHookCtx

    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.

    Cells

    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.

    Column

    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.

    Columns

    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.

    Ctx

    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.

    DataTable

    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.

    DocString

    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.

    FeatureResult

    Result of executing a feature.

    FeatureSource

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

    HookError

    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.

    HookHandler

    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.

    HookRegistry

    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.

    HookResult

    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.

    HookType

    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.

    PendingAttachment

    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.

    RegisteredHook

    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.

    Row

    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.

    Rows

    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.

    RunHookCtx

    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.

    RunOptions

    Options for configuring a test run.

    RunResult

    Complete result of a test run.

    RunSummary

    Summary of an entire run.

    The retried field counts scenarios that required more than one attempt, regardless of their final outcome. A scenario that fails on the first attempt but passes on retry is counted as both passed and retried.

    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.

    Setup

    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.

    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.

    StepHookCtx

    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.

    StepValue

    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.

    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

    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. Lifecycle hooks registered via Setup are called automatically when present.

    run_or_fail

    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.

    Source Files