smoothy

Crates.iosmoothy
lib.rssmoothy
version0.10.0
created_at2023-11-14 15:25:09.510625+00
updated_at2025-12-29 15:21:43.462309+00
descriptionWrite smooth assertions in a fluent and human readable way
homepagehttps://github.com/open-schnick/smoothy
repositoryhttps://github.com/open-schnick/smoothy
max_upload_size
id1034918
size177,954
Open Schnick (open-schnick)

documentation

https://docs.rs/smoothy

README

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 easier to work with

Why Smoothy?

Standard Rust assertions are quite minimalistic and lack meaningful error messages. Which makes debugging failing tests really hard.

Take the following assertion:

let result: Result<(), String> = Err("Some Error".to_string());

assert!(result.is_ok());

This will result in a panic that looks like this:

thread 'test' panicked at src/lib.rs:42:5:
assertion failed: result.is_ok()

well... what is the error here?

Without knowing this, one has to rerun the test with logging or a debugger to find out why the assertion failed.

The same assertion looks like this in Smoothy:

use smoothy::prelude::*;

let result: Result<(), String> = Err("Some Error".to_string());

assert_that(result).is_ok();

which leads to the following output:

thread 'test' panicked at src/lib.rs:42:5:
Assertion failed!

Expected
  Err("Some Error")
to be Ok

The output of the default assertions is even worse when you want to assert iterators:

let vec: Vec<i32> = vec![1, 2, 3];

assert!(vec.contains(&4));
thread 'test' panicked at src/lib.rs:42:5:
assertion failed: vec.contains(&4)

with Smoothy:

use smoothy::prelude::*;

let vec: Vec<i32> = vec![1, 2, 3];

assert_that(vec).contains(4);
thread 'test' panicked at src/lib.rs:42:5:
Assertion failed!

Expected
  [1, 2, 3]
to contain
  4

How does it work

Start asserting by calling assert_that on a value. Then chain assertions based on the type you are asserting.

use smoothy::prelude::*;

assert_that("Hello World!").starts_with("Hello").and().contains("World!");

Smoothy uses traits to implement different assertions depending on the type you are asserting. This way you can only write assertions that make sense

use smoothy::prelude::*;

// this obviously makes no sense
assert_that(42).is_true();

Smoothy provides a lot of different assertions documented here.

If you are missing some assertions feel free to open an issue or a pull request :)

Commit count: 141

cargo fmt