Sign in

    moonspec

    BDD test framework for MoonBit with Gherkin and Cucumber Expressions

    bdd
    cucumber
    gherkin
    testing
    moonbit
    Download zip
    Author
    Version
    0.1.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
    let result = @moonspec.run(
    CalcWorld::default,
    [@moonspec.FeatureSource::Text("test://calculator", feature)],
    )
    assert_eq(result.summary.passed, 1)
    }

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

    #Features

    • World trait -- per-scenario state isolation following cucumber-rs patterns
    • 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

    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.

    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.

    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.

    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.

    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.

    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_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