Crates.io | snaptest |
lib.rs | snaptest |
version | 0.2.0 |
source | src |
created_at | 2018-03-19 01:20:54.23281 |
updated_at | 2018-03-21 01:37:09.836921 |
description | Dead simple snapshot testing |
homepage | |
repository | https://github.com/zacharygolba/snaptest |
max_upload_size | |
id | 56341 |
size | 402,422 |
Dead simple snapshot testing (inspired by jest).
Documentation (including this README) is a work in progress. Feel free to submit an issue if you have a question about usage.
Debug
can be returned from a test.failure
.TODO
First, add snaptest
to the dependencies section of your Cargo.toml
:
[dependencies]
snaptest = "0.1"
Next, add the following snippet to the entry point of your crate (lib.rs
or main.rs
):
#[macro_use]
extern crate snaptest;
Derive Debug
on types that you want to use with snaptest:
use std::str::FromStr;
#[derive(Debug)]
pub struct User {
connection: Connection,
name: String,
}
#[derive(Debug)]
pub enum Connection {
Online,
Offline,
}
impl FromStr for User {
// ...
}
Now, in the test module for the User
struct:
snaptest!{
fn parse_user() -> Result<User, Error> {
"Zak:online".parse()
}
}
Next time your test runs, a snapshot will be added to a local .snapfile
to compare against future test results. If you get a different result back than what matches the snapshot, the test will fail and the diff will be printed to the console.
Licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.