Expand description
BDD test framework for Lua on mlua.
Embeds a forked copy of lust (MIT, single-file, zero-dependency) and provides Rust APIs for executing tests and collecting structured results.
Includes spy/stub/mock test doubles implemented as Rust UserData.
§Quick start
let summary = mlua_lspec::run_tests(r#"
local describe, it, expect = lust.describe, lust.it, lust.expect
describe('example', function()
it('works', function()
expect(1 + 1).to.equal(2)
end)
end)
"#, "@test.lua").unwrap();
assert_eq!(summary.passed, 1);
assert_eq!(summary.failed, 0);§Granular control
For advanced use cases (e.g. registering lust on a pre-existing
VM or running multiple test suites in sequence), use
register and collect_results directly instead of
run_tests.
use mlua::prelude::*;
use mlua_lspec::{register, register_doubles, collect_results};
let lua = Lua::new();
register(&lua).unwrap();
register_doubles(&lua).unwrap();
lua.load(r#"
local describe, it, expect = lust.describe, lust.it, lust.expect
describe('inline', function()
it('works', function()
expect(42).to.equal(42)
end)
end)
"#).exec().unwrap();
let summary = collect_results(&lua).unwrap();
assert_eq!(summary.passed, 1);§Test doubles
The doubles module provides Rust-backed spy, stub, and mock
objects exposed as Lua UserData. These are registered
automatically by run_tests as the test_doubles global table.
local s = test_doubles.spy(function(x) return x * 2 end)
s(5)
assert(s:call_count() == 1)
assert(s:was_called_with(5))
local st = test_doubles.stub()
st:returns(42)
assert(st() == 42)Re-exports§
pub use doubles::register as register_doubles;pub use framework::collect_results;pub use framework::register;pub use framework::run_tests;
Modules§
Structs§
- Test
Result - Result of a single test case.
- Test
Summary - Aggregated results from a test run.