aboutsummaryrefslogtreecommitdiffstats
path: root/testing/tests/rocket.rs
blob: c613311969e7d5e90a3c6bb6829927c79f475adc (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#![cfg(feature = "rocket")]
#![feature(plugin)]
#![plugin(rocket_codegen)]

#[macro_use]
extern crate askama;
extern crate rocket;

use askama::Template;

use rocket::http::{ContentType, Status};
use rocket::local::Client;

#[derive(Template)]
#[template(path = "hello.html")]
struct HelloTemplate<'a> {
    name: &'a str,
}

#[get("/")]
fn hello() -> HelloTemplate<'static> {
    HelloTemplate { name: "world" }
}

#[test]
fn test_rocket() {
    let rocket = rocket::ignite().mount("/", routes![hello]);
    let client = Client::new(rocket).unwrap();
    let mut rsp = client.get("/").dispatch();
    assert_eq!(rsp.status(), Status::Ok);
    assert_eq!(rsp.content_type(), Some(ContentType::HTML));
    assert_eq!(rsp.body_string().unwrap(), "Hello, world!");
}