Smoothy
Write smooth assertions in a fluent and readable way.
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: = Err;
assert!;
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 *;
let result: = Err;
assert_that.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!;
assert!;
thread 'test' panicked at src/lib.rs:42:5:
assertion failed: vec.contains(&4)
with Smoothy:
use *;
let vec: = vec!;
assert_that.contains;
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 *;
assert_that.starts_with.and.contains;
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 *;
// this obviously makes no sense
assert_that.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 :)