#assertions #fluent #assert #human-readable

smoothy

Write smooth assertions in a fluent and human readable way

17 unstable releases (6 breaking)

0.7.0 Dec 15, 2024
0.5.2 Nov 27, 2024
0.4.4 May 15, 2024
0.4.3 Mar 3, 2024
0.3.0 Nov 27, 2023

#261 in Testing

Download history 51/week @ 2024-09-14 9/week @ 2024-09-21 41/week @ 2024-09-28 5/week @ 2024-10-05 3/week @ 2024-10-26 16/week @ 2024-11-09 9/week @ 2024-11-16 158/week @ 2024-11-23 47/week @ 2024-11-30 36/week @ 2024-12-07 263/week @ 2024-12-14 11/week @ 2024-12-21

313 downloads per month
Used in datadog-formatting-layer

MIT license

46KB
444 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

Example

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::prelude::*;

assert_that(42).equals(42);
assert_that(true).is_true();
assert_that(String::from("Hello")).equals("Hello");

More examples on docs.rs

Assertion Structure Diagram

stateDiagram-v2
    [*] --> BasicAsserter&ltAssertable&gt : assert_that
    BasicAsserter&ltAssertable&gt --> Anything
    state "Assertable is any type" as Anything {
        [*] --> AssertionConnector&ltAssertable&gt : is
        [*] --> AssertionConnector&ltAssertable&gt : is_not
        [*] --> AssertionConnector&ltAssertable&gt : equals
        [*] --> AssertionConnector&ltAssertable&gt : not_equals
        [*] --> AssertionConnector&ltAssertable&gt : try_into_equals
        [*] --> AssertionConnector&ltAssertable&gt : try_into_not_equals
        [*] --> AssertionConnector&ltAssertable&gt : map
        AssertionConnector&ltAssertable&gt --> [*] : and
    }
    BasicAsserter&ltAssertable&gt --> Result
    state "Assertable is Result&ltOk, Err&gt" as Result {
        [*] --> OkAsserter&ltOk&gt : is_ok
        OkAsserter&ltOk&gt --> BasicAsserter&ltOk&gt : and_value
        [*] --> ErrAsserter&ltErr&gt : is_err
        ErrAsserter&ltErr&gt --> BasicAsserter&ltErr&gt : and_error
    }
    BasicAsserter&ltAssertable&gt --> Option
    state "Assertable is Option&ltSome&gt" as Option {
        [*] --> [*] : is_none
        [*] --> SomeAsserter&ltSome&gt : is_some
        SomeAsserter&ltSome&gt --> BasicAsserter&ltSome&gt : and_value
    }
    BasicAsserter&ltAssertable&gt --> ImplString
    state "Assertable implements ToString" as ImplString {
        [*] --> BasicAsserter&ltString&gt : to_string
    }
    BasicAsserter&ltAssertable&gt --> ImplToBool
    state "Assertable implements Into<bool>" as ImplToBool {
        [*] --> BasicAsserter&ltbool&gt : is_true
        [*] --> BasicAsserter&ltbool&gt : is_false
    }
    BasicAsserter&ltAssertable&gt --> ImplAsRefStr
    state "Assertable implements AsRef&ltstr&gt" as ImplAsRefStr {
        [*] --> AssertionConnector&ltAsRef&ltstr&gt&gt : contains_string
        [*] --> AssertionConnector&ltAsRef&ltstr&gt&gt : starts_with_string
        [*] --> AssertionConnector&ltAsRef&ltstr&gt&gt : is_matching
        AssertionConnector&ltAsRef&ltstr&gt&gt --> [*] : and
    }
    BasicAsserter&ltAssertable&gt --> ImplIntoIter
    state "Assertable implements IntoIter&ltItem&gt" as ImplIntoIter {
        [*] --> [*] : is_empty
        [*] --> [*] : is_not_empty
        [*] --> BasicAsserter&ltItem&gt: first
        [*] --> BasicAsserter&ltItem&gt: second
        [*] --> BasicAsserter&ltItem&gt: third
        [*] --> BasicAsserter&ltItem&gt: nth
    }

Dependencies

~2.3–3.5MB
~55K SLoC