Skip to main content

Crate rsspec

Crate rsspec 

Source
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 with cargo test
  • bdd! — generates a main() 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) — enables suite!, bdd!, bdd_suite! macros
  • googletest — re-exports googletest matchers via rsspec::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() — returns Vec<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§

AfterAllGuard
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_FOCUS is set and focus mode is active.
check_labels
Check if the current test’s labels match the RSSPEC_LABEL_FILTER env var.
defer_cleanup
Register a cleanup function that will run after the current test completes.
must_pass_repeatedly
Require a test to pass n consecutive 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 retries additional times on failure.
with_timeout
Run a test with a timeout (in milliseconds).