An assertions/expectations library for Rust. expect
provides a syntax
inspired by RSpec
and Gomega, and a set of powerful built-in
matchers.
expect
isn't ready for general use just yet, but you can try it by consuming
this Git repository in your Cargo.toml
:
[dev-dependencies]
expect = { git = "https://github.com/gcapizzi/expect.git" }
The basic structure of an expectation is:
expect(&actual).to(matcher(expected));
expect(&actual).not_to(matcher(expected));
For example:
expect(&(2 + 2)).to(equal(4))
equal
:expect(&"foo").to(equal("foo"))
match_regex
:expect(&"abc-123").to(match_regex(r"\d{3}"));
contain
:expect(&[1, 2, 3]).to(contain(2)); expect(&vec![1, 2, 3]).not_to(contain(4));
be_empty
:expect(&Vec::<i32>::new()).to(be_empty());
be_some
:expect(&Some("foo")).to(be_some());
be_none
:expect(&None::<&str>).to(be_none());
be_ok
:expect(&Ok("foo")).to(be_ok());
be_err
:expect(&Err("foo")).to(be_err());
exist
:expect(&env!("CARGO_HOME")).to(exist());