#fluent-assertions #assert #fluent #assertions

smoothy

Write smooth assertions in a fluent and human readable way

23 releases

0.8.5 Nov 2, 2025
0.8.3 Apr 12, 2025
0.8.1 Mar 7, 2025
0.7.0 Dec 15, 2024
0.3.0 Nov 27, 2023

#189 in Testing

Download history 18/week @ 2025-08-20 14/week @ 2025-09-03 83/week @ 2025-09-10 24/week @ 2025-09-17 21/week @ 2025-09-24 50/week @ 2025-10-01 37/week @ 2025-10-08 8/week @ 2025-10-15 177/week @ 2025-10-22 7/week @ 2025-10-29

232 downloads per month
Used in datadog-formatting-layer

MIT license

83KB
908 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 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 :)

Dependencies

~2–13MB
~115K SLoC