9 releases

0.2.1 Aug 8, 2021
0.2.0 Jul 6, 2021
0.1.0 Jul 5, 2021
0.0.6 Jul 3, 2021
0.0.5 Jun 15, 2021

#216 in Testing

Download history 24/week @ 2021-06-27 84/week @ 2021-07-04 7/week @ 2021-07-11 47/week @ 2021-07-18 37/week @ 2021-07-25 27/week @ 2021-08-01 61/week @ 2021-08-08 33/week @ 2021-08-15 13/week @ 2021-08-22 26/week @ 2021-08-29 12/week @ 2021-09-05 1/week @ 2021-09-12 25/week @ 2021-09-19 10/week @ 2021-09-26 39/week @ 2021-10-03 24/week @ 2021-10-10

141 downloads per month
Used in 3 crates

Apache-2.0

135KB
1.5K SLoC

asserhttp

Fluent http response assertions


A standard trait for doing fluent assertions over many http client response. Currently, supports actix-web, reqwest, hyper, awc (Actix Web Client), surf and isahc.

Getting started

Add it to your Cargo.toml

asserhttp = { version = "0.2.1", features = ["reqwest"] }
#                             or features = ["hyper"]
#                             or features = ["actix"]
#                             or features = ["surf"]
#                             or features = ["isahc"]

Then use it in your tests, for example on actix-web,

use actix_web::{App, HttpResponse, test::{call_service, init_service, TestRequest}, web};
use asserhttp::*;

#[actix_rt::test]
async fn sample_test() {
    let app = App::new().route("/", web::get().to(|| async { HttpResponse::Ok().body(json!({"a": "b"})) }));
    call_service(&mut init_service(app).await, TestRequest::get().to_request()).await
        .expect_status_ok()
        .expect_content_type_json()
        .expect_body_json_eq(json!({"a": "b"}));
}

or on reqwest

use reqwest;
use asserhttp::*;

#[tokio::test]
async fn my_test() {
    reqwest::get("http://localhost").await
        .expect_status_ok()
        .expect_content_type_json()
        .expect_body_json_eq(json!({"name": "jdoe"}));
}

Dependencies

~3–11MB
~244K SLoC