BDD test framework for MoonBit with Gherkin and Cucumber Expressions
moon add moonrockz/moonspecstruct 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
}| Package | Description |
|---|---|
| moonrockz/moonspec | Top-level facade -- World, Setup, Ctx, RunOptions, run, run_or_fail |
| moonrockz/moonspec/core | World trait, Setup facade, HookRegistry, StepRegistry, Ctx types |
| moonrockz/moonspec/runner | Feature/scenario executor with tag filtering and parallel support |
| moonrockz/moonspec/format | Formatter trait + Pretty, Messages, JUnit implementations |
| moonrockz/moonspec/codegen | Generate test files from Gherkin features |
Install
Download zipBDD test framework for MoonBit with Gherkin and Cucumber Expressions