Crates.io | rest |
lib.rs | rest |
version | 0.5.1 |
created_at | 2025-04-27 09:35:44.438031+00 |
updated_at | 2025-04-27 09:35:44.438031+00 |
description | A fluent, Jest-like testing library for Rust |
homepage | |
repository | https://github.com/mister-good-deal/rest |
max_upload_size | |
id | 1650979 |
size | 274,957 |
A fluent, Jest-like testing library for Rust that builds upon the standard testing infrastructure. Rest provides expressive assertions with readable error messages while maintaining compatibility with Rust's built-in testing functionality.
.and()
and .or()
operators.Add Rest to your project:
cargo add rest --dev
Write your first test:
use rest::prelude::*;
#[test]
fn should_check_values() {
// By default, Rest behaves like standard Rust assertions
// To enable enhanced output, configure it:
config().enhanced_output(true).apply();
let my_number = 5;
let my_string = "hello world";
let my_vec = vec![1, 2, 3];
expect!(my_number).to_be_greater_than(3);
expect!(my_string).to_contain("world");
expect!(my_vec).to_have_length(3);
}
You can also enable enhanced output globally by setting the environment variable:
REST_ENHANCED_OUTPUT=true cargo test
Rest provides a comprehensive set of matchers for various types. All matchers support negation through either the
not()
method or the expect_not!
macro.
For complete documentation of all matchers, please see the Wiki documentation.
View Boolean Matchers documentation
View Equality Matchers documentation
View Numeric Matchers documentation
View String Matchers documentation
View Collection Matchers documentation
View HashMap Matchers documentation
View Option Matchers documentation
View Result Matchers documentation
Rest provides powerful modifiers to create complex assertions, including:
.not()
method or expect_not!
macro.and()
and .or()
operators// Example of chained assertions
expect!(number).to_be_greater_than(30)
.and().to_be_less_than(50)
.and().to_be_even();
// Example of negation
expect!(value).not().to_equal(100);
View Using Modifiers documentation
Rest provides a powerful fixture system for setting up and tearing down test environments:
use rest::prelude::*;
// Define setup function
#[setup]
fn prepare_test_data() {
// Code to run before each test
println!("Setting up test environment");
}
// Define teardown function
#[tear_down]
fn cleanup_resources() {
// Code to run after each test
println!("Cleaning up test environment");
}
// Test with fixtures
#[test]
#[with_fixtures]
fn my_test() {
// This will automatically run setup before and teardown after
expect!(2 + 2).to_equal(4);
}
Key features:
#[before_all]
, #[setup]
, #[tear_down]
, and #[after_all]
#[setup]
, #[tear_down]
, and #[with_fixtures]
#[with_fixtures_module]
to apply fixtures to all tests in a moduleView Test Fixtures documentation
Rest is designed to be easily extensible. You can create your own custom matchers to make your tests more expressive and domain-specific.
View Custom Matchers documentation
Rest enhances the standard test output with colors, symbols, and improved formatting:
&
) are automatically removed from outputView Output Formatting documentation
Rest uses a modular, event-driven architecture:
View Architecture documentation
This project is automatically published to crates.io when:
The publishing workflow will:
This project uses Rust's official LLVM-based code coverage instrumentation to track test coverage. The coverage workflow:
-C instrument-coverage
flagCoverage reports are automatically generated on each push to the master branch and for pull requests.
To generate coverage reports locally:
# Install required components
rustup component add llvm-tools-preview
cargo install grcov
cargo install rustfilt
# Build with coverage instrumentation and run tests
RUSTFLAGS="-C instrument-coverage" cargo test
# Generate HTML report
grcov . --binary-path ./target/debug/ -s . -t html --branch --keep-only "src/**" -o ./coverage
# Generate Markdown report
grcov . --binary-path ./target/debug/ -s . -t markdown --branch --keep-only "src/**" -o ./coverage/coverage.md
Then open ./coverage/index.html
in your browser or view the Markdown report in your favorite editor.
This project is licensed under the MIT License - see the LICENSE file for details.