Spec "it" for Rust testing
```toml
[dev-dependencies] specit = "0.3.0" ```
```rust use specit::it;
fn t() { assert_eq!(2 + 2, 4); }
fn t() { assert_eq!(1 + 1, 3); } ```
The test output is like the following.
``` running 2 tests test shouldbecorrect ... ok test shouldbewrong ... ok
test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out ```
```rust use specit::describe;
mod m { use specit::it;
#[it("should add two numbers")]
pub fn t() {
assert_eq!(2 + 2, 4);
}
#[it("should multiple two numbers")]
pub fn t() {
assert_eq!(3 * 3, 9);
}
} ```
The test output with describe
is like the following.
``` running 2 tests test arithmeticoperations::shouldaddtwonumbers ... ok test arithmeticoperations::shouldmultipletwonumbers ... ok
test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out ```
You can test with #[tokio::test]
for asynchronous functions.
```rust
use specit::it;
async fn t() { let f = async { 10 }; assert_eq!(f.await, 10); } ```
You can get short your code using the following features in each asynchronous runtime.
features = ["tokio"]
You can use use specit::tokio_it as it
for testing asynchronous functions without #[tokio::test]
like the following.
```rust use specit::tokio_it as it;
async fn t() { let f = async { 10 }; assert_eq!(f.await, 10); } ```
features = ["async-std"]
Use #[it(...)]
instead of #[async_std::test]
as follows.
```rust use specit::asyncstdit as it;
async fn t() { let f = async { 10 }; assert_eq!(f.await, 10); } ```
features = ["lib-wasm-bindgen"]
Use #[it(...)]
instead of #[wasm_bindgen_test::wasm_bindgen_test]
as follows.
```rust use specit::wasmbindgentestit as it; use wasmbindgen::prelude::JsValue; use wasmbindgenfutures::JsFuture;
async fn t() { let promise = jssys::Promise::resolve(&JsValue::from(42)); let x = JsFuture::from(promise).await.unwrap(); asserteq!(x, 42); } ```
Internally, the functions above are should_be_correct()
and should_be_wrong()
. You can use any string. Non-alphanum characters are encoded into '_'
.