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
313 downloads per month
Used in datadog-formatting-layer
46KB
444 lines
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 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<Assertable> : assert_that
BasicAsserter<Assertable> --> Anything
state "Assertable is any type" as Anything {
[*] --> AssertionConnector<Assertable> : is
[*] --> AssertionConnector<Assertable> : is_not
[*] --> AssertionConnector<Assertable> : equals
[*] --> AssertionConnector<Assertable> : not_equals
[*] --> AssertionConnector<Assertable> : try_into_equals
[*] --> AssertionConnector<Assertable> : try_into_not_equals
[*] --> AssertionConnector<Assertable> : map
AssertionConnector<Assertable> --> [*] : and
}
BasicAsserter<Assertable> --> Result
state "Assertable is Result<Ok, Err>" as Result {
[*] --> OkAsserter<Ok> : is_ok
OkAsserter<Ok> --> BasicAsserter<Ok> : and_value
[*] --> ErrAsserter<Err> : is_err
ErrAsserter<Err> --> BasicAsserter<Err> : and_error
}
BasicAsserter<Assertable> --> Option
state "Assertable is Option<Some>" as Option {
[*] --> [*] : is_none
[*] --> SomeAsserter<Some> : is_some
SomeAsserter<Some> --> BasicAsserter<Some> : and_value
}
BasicAsserter<Assertable> --> ImplString
state "Assertable implements ToString" as ImplString {
[*] --> BasicAsserter<String> : to_string
}
BasicAsserter<Assertable> --> ImplToBool
state "Assertable implements Into<bool>" as ImplToBool {
[*] --> BasicAsserter<bool> : is_true
[*] --> BasicAsserter<bool> : is_false
}
BasicAsserter<Assertable> --> ImplAsRefStr
state "Assertable implements AsRef<str>" as ImplAsRefStr {
[*] --> AssertionConnector<AsRef<str>> : contains_string
[*] --> AssertionConnector<AsRef<str>> : starts_with_string
[*] --> AssertionConnector<AsRef<str>> : is_matching
AssertionConnector<AsRef<str>> --> [*] : and
}
BasicAsserter<Assertable> --> ImplIntoIter
state "Assertable implements IntoIter<Item>" as ImplIntoIter {
[*] --> [*] : is_empty
[*] --> [*] : is_not_empty
[*] --> BasicAsserter<Item>: first
[*] --> BasicAsserter<Item>: second
[*] --> BasicAsserter<Item>: third
[*] --> BasicAsserter<Item>: nth
}
Dependencies
~2.3–3.5MB
~55K SLoC