Announcing lets_expect - Clean tests in Rust.

127 points tomekpiotrowski
expect(a + 2) {
    when(a = 2) {
        to equal(4)
    }
}

Github docs.rs

How often when you see a Rust test you think to yourself "wow, this is a really beautifully written test"? Not often, right? Classic Rust tests do not provide any structure beyond the test function itself. This often results in a lot of boilerplate code, ad-hoc test structure and overall poor quality.

Tests are about verifying that a given piece of code run under certain conditions works as expected. A good testing framework embraces this way of thinking. It makes it easy to structure your code in a way that reflects it. Folks in other communities have been doing this for a long time with tools like RSpec and Jasmine.

If you want beautiful, high-quality tests that are a pleasure to read and write you need something else. Using Rust's procedural macros lets\_expect introduces a syntax that let's you clearly state what you're testing, under what conditions and what is the expected result.

The outcome is:

  • easy to read, DRY, TDD-friendly tests
  • less boilerplate, less code
  • nicer error messages
  • more fun