Code Monkey home page Code Monkey logo

speculate-rs's Introduction

speculate2

An RSpec inspired minimal testing framework for Rust. (This is an updated and partially rewritten fork for Rust 2021, with updated dependencies and removed unstable functionality.)

Originally developed by Utkarsh Kukreti.

Build Status MIT licensed crates.io docs.rs

Installation

Add speculate to the dev-dependencies section of your Cargo.toml:

[dev-dependencies]
speculate2 = "0.2"

And add the following to the top of the Rust file you want to add tests for:

#[cfg(test)]
use speculate2::speculate;  // Must be imported into the current scope.

Usage

Speculate provides the speculate! syntax extension. Inside speculate! { ... }, you can have any "Item", like static, const, fn, etc, and 5 special types of blocks:

  • describe (or its alias context) - to group tests in a hierarchy, for readability. Can be arbitrarily nested.

  • before and after - contain setup / teardown code that's inserted before / after every sibling and nested it block.

  • it (or its alias test) - contains tests.

    For example:

    it "can add 1 and 2" {
        assert_eq!(1 + 2, 3);
    }

    You can optionally add attributes to this block:

    #[ignore]
    test "ignore" {
        assert_eq!(1, 2);
    }
    
    #[should_panic]
    test "should panic" {
        assert_eq!(1, 2);
    }
    
    #[should_panic(expected = "foo")]
    test "should panic with foo" {
        panic!("foo");
    }

License

Licensed same as the original repository, under MIT License. A copy can be found in the repo root.

speculate-rs's People

Contributors

utkarshkukreti avatar alexobolev avatar 71 avatar k-nasa avatar gilescope avatar ms-ati avatar pinkfloyded avatar palfrey avatar

Stargazers

Gianluca Costa avatar Dylan Cromer avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.