#assert #assertions #fluent #tests

smoothy

Write smooth assertions in a fluent and human readable way

4 releases (2 breaking)

new 0.3.1 Dec 4, 2023
0.3.0 Nov 27, 2023
0.2.0 Nov 19, 2023
0.1.0 Nov 14, 2023

#167 in Testing

Download history 28/week @ 2023-11-11 30/week @ 2023-11-18 52/week @ 2023-11-25

110 downloads per month

MIT license

51KB
268 lines

Smoothy

Write smooth assertions in a fluent and readable way.

check test License Crates.io

Features

The crate is heavily inspired by AssertJ

  • simple and readable syntax
  • assertions based on the type of the asserted value
  • assertion values use type conversion traits to make assertions readable

Examples

All asserted are stared by calling assert_that on a value.
After that various assertions based on the type of the asserted value can be made.

use smoothy::assert_that;

assert_that(42).equals(42);
use smoothy::assert_that;

assert_that(1u8).try_into_equals(1i8);
use smoothy::assert_that;

assert_that(String::from("Hello")).equals("Hello");
use smoothy::assert_that;

let result: Result<u8, String> = Ok(42);
assert_that(result)
    .is_ok()
    .and_value()
    .equals(42);
use smoothy::assert_that;

let result: Result<(), String> = Err(String::from("ups!"));
assert_that(result)
    .is_err()
    .and_error()
    .to_string()
    .equals("ups!");
use smoothy::assert_that;

let option: Option<()> = None;
assert_that(option).is_none();
use smoothy::assert_that;

let option: Option<u8> = Some(1);
assert_that(option)
    .is_some()
    .and_value()
    .equals(1)

TODO:

  • vec support (length, contains)
  • string support (length, contains, starts_with, ends_with)

Dependencies

~210KB