Skip to content

An assertions/expectations library for Rust.

Notifications You must be signed in to change notification settings

gcapizzi/expect

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

59 Commits
 
 
 
 
 
 
 
 

Repository files navigation

expect

An assertions/expectations library for Rust. expect provides a syntax inspired by RSpec and Gomega, and a set of powerful built-in matchers.

Getting expect

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" }

Using expect

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))

Built-in matchers

Core matchers

  • equal:
    expect(&"foo").to(equal("foo"))

String matchers

  • match_regex:
    expect(&"abc-123").to(match_regex(r"\d{3}"));

Collection matchers

  • 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());

Option matchers

  • be_some:
    expect(&Some("foo")).to(be_some());
  • be_none:
    expect(&None::<&str>).to(be_none());

Result matchers

  • be_ok:
    expect(&Ok("foo")).to(be_ok());
  • be_err:
    expect(&Err("foo")).to(be_err());

Path matchers

  • exist:
    expect(&env!("CARGO_HOME")).to(exist());

About

An assertions/expectations library for Rust.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages