speculate2

Crates.iospeculate2
lib.rsspeculate2
version0.2.0
sourcesrc
created_at2022-11-27 10:18:33.235884
updated_at2022-11-27 10:18:33.235884
descriptionAn updated fork of `speculate`, an RSpec inspired minimal testing framework for Rust.
homepage
repositoryhttps://github.com/alexobolev/speculate-rs
max_upload_size
id723653
size21,955
Alex Sobolev (alexobolev)

documentation

README

speculate2

An RSpec inspired minimal testing framework for Rust. (This is an updated and partially rewritten fork for Rust 2021, with updated dependencies and removed unstable functionality.)

Build Status MIT licensed

Installation

Add speculate to the dev-dependencies section of your Cargo.toml:

[dev-dependencies]
speculate2 = "0.2"

And add the following to the top of the Rust file you want to add tests for:

#[cfg(test)]
use speculate2::speculate;  // Must be imported into the current scope.

Usage

Speculate provides the speculate! syntax extension. Inside speculate! { ... }, you can have any "Item", like static, const, fn, etc, and 5 special types of blocks:

  • describe (or its alias context) - to group tests in a hierarchy, for readability. Can be arbitrarily nested.

  • before and after - contain setup / teardown code that's inserted before / after every sibling and nested it block.

  • it (or its alias test) - contains tests.

    For example:

    it "can add 1 and 2" {
        assert_eq!(1 + 2, 3);
    }
    

    You can optionally add attributes to this block:

    #[ignore]
    test "ignore" {
        assert_eq!(1, 2);
    }
    
    #[should_panic]
    test "should panic" {
        assert_eq!(1, 2);
    }
    
    #[should_panic(expected = "foo")]
    test "should panic with foo" {
        panic!("foo");
    }
    

License

Licensed same as the original repository, under MIT License. A copy can be found in the repo root.

Commit count: 166

cargo fmt