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 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)
}| Package | Description |
|---|---|
| moonrockz/moonspec | Top-level facade -- World, Hooks, StepArg, run, run_with_hooks |
| moonrockz/moonspec/core | World and Hooks traits, StepRegistry, StepArg 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 |
async fn[W : World] run(factory : () -> W, features : Array[FeatureSource], tag_expr? : String, scenario_name? : String, parallel? : Int) -> RunResultasync fn[W : World + Hooks] run_with_hooks(factory : () -> W, features : Array[FeatureSource], tag_expr? : String, scenario_name? : String, parallel? : Int) -> RunResultInstall
Download zipBDD test framework for MoonBit with Gherkin and Cucumber Expressions