Skip to content

AverSpec/aver-rs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Aver for Rust

Domain-driven acceptance testing for Rust.

Install

Add to your Cargo.toml:

[dev-dependencies]
averspec = "0.1"

Quick Example

use averspec::*;

// Domain markers
struct TaskMarkers {
    create_task: Action<String>,
    task_exists: Assertion<String>,
    task_count:  Query<(), usize>,
}

fn make_markers() -> TaskMarkers {
    TaskMarkers {
        create_task: Action::new("create_task"),
        task_exists: Assertion::new("task_exists"),
        task_count:  Query::new("task_count"),
    }
}

// Adapter + Protocol + Suite
fn make_suite() -> Suite<TaskMarkers, Vec<String>> {
    let m = make_markers();
    let mut b = AdapterBuilder::new();

    b.on_action(&m.create_task, |ctx: &mut Vec<String>, title: &String| {
        ctx.push(title.clone());
    });
    b.on_query(&m.task_count, |ctx: &mut Vec<String>, _: &()| ctx.len());
    b.on_assertion(&m.task_exists, |ctx: &mut Vec<String>, title: &String| {
        if ctx.contains(title) {
            Ok(())
        } else {
            Err(format!("task not found: {title}"))
        }
    });

    let adapter = b.build();
    let protocol = UnitProtocol::new("unit", || Vec::<String>::new());

    Suite::new("Tasks", m, adapter, Box::new(protocol))
}

// Tests
#[test]
fn create_task() {
    let s = make_suite();
    s.run("create and verify a task", |m, t| {
        t.when(&m.create_task, "Fix bug".into());
        t.then(&m.task_exists, "Fix bug".into());
    });
    assert!(s.finish().all_passed());
}

Run with cargo:

cargo test

Links

About

Domain-driven acceptance testing for Rust

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages