Expand description
§rsspec — A Ginkgo/RSpec-inspired BDD testing framework for Rust
Write expressive, structured tests using a familiar BDD syntax with
describe, context, it, lifecycle hooks, table-driven tests, and more.
§Three ways to run tests
suite!— generates#[test]functions, works withcargo testbdd!— generates amain()with colored tree output (harness = false)bdd_suite!— returns test nodes for combining multiple suites
§Quick example
rsspec::suite! {
describe "Calculator" {
before_each {
let a = 2;
let b = 3;
}
subject { a + b }
it "adds two numbers" {
assert_eq!(subject, 5);
}
context "with negative numbers" {
it "handles negatives" {
assert_eq!(-1 + b, 2);
}
}
}
}§Features
macros(default) — enablessuite!,bdd!,bdd_suite!macrosgoogletest— re-exportsgoogletestmatchers viarsspec::matchers
See the suite! macro documentation for the full DSL reference.
Modules§
- runner
- BDD-style test runner with colored, indented tree output.
Macros§
- bdd
- BDD test runner macro — generates a
main()function with colored tree output. - bdd_
suite - Generate a test tree without
fn main()— returnsVec<rsspec::runner::TestNode>. - by
- Document a step within a test (macro form).
- skip
- Skip the current test at runtime. Prints the reason and returns from the test.
- suite
- A Ginkgo/RSpec-inspired BDD test suite macro.
Structs§
- After
AllGuard - Helper for after_all: tracks how many tests in a scope have completed.
When the count reaches
total, the cleanup function runs. - Guard
- A drop guard that runs cleanup code (after_each) even if the test panics.
Functions§
- by
- Document a step within a test. Prints the step description to stderr.
- check_
fail_ on_ focus - Panics if
RSSPEC_FAIL_ON_FOCUSis set and focus mode is active. - check_
labels - Check if the current test’s labels match the
RSSPEC_LABEL_FILTERenv var. - defer_
cleanup - Register a cleanup function that will run after the current test completes.
- must_
pass_ repeatedly - Require a test to pass
nconsecutive times. If any run fails, the test fails. - run_
deferred_ cleanups - Run all deferred cleanup functions. Called automatically by generated test code.
- skip
- Skip the current test at runtime with a reason.
- with_
retries - Retry a test function up to
retriesadditional times on failure. - with_
timeout - Run a test with a timeout (in milliseconds).