From e0300661068f3c8141cdc90fa915f7c61ce3d1ab Mon Sep 17 00:00:00 2001 From: Dirkjan Ochtman Date: Wed, 23 Aug 2017 16:32:28 +0200 Subject: Add test for Rocket support --- testing/Cargo.toml | 6 ++++++ testing/tests/rocket.rs | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 testing/tests/rocket.rs diff --git a/testing/Cargo.toml b/testing/Cargo.toml index 6d81db5..8db4cd5 100644 --- a/testing/Cargo.toml +++ b/testing/Cargo.toml @@ -5,10 +5,16 @@ authors = ["Dirkjan Ochtman "] workspace = ".." build = "build.rs" +[features] +default = [] +nightly = ["rocket", "rocket_codegen", "askama/with-rocket"] + [dependencies] iron = "0.5" serde_json = "1.0" askama = { path = "../askama", version = "*", features = ["with-iron", "serde-json"] } +rocket = { version = "0.3", optional = true } +rocket_codegen = { version = "0.3", optional = true } [build-dependencies] askama = { path = "../askama", version = "*", features = ["with-iron", "serde-json"] } diff --git a/testing/tests/rocket.rs b/testing/tests/rocket.rs new file mode 100644 index 0000000..19c1d78 --- /dev/null +++ b/testing/tests/rocket.rs @@ -0,0 +1,33 @@ +#![cfg(feature = "rocket")] +#![feature(plugin)] +#![plugin(rocket_codegen)] + +#[macro_use] +extern crate askama; +extern crate rocket; + +use askama::Template; + +use rocket::local::Client; +use rocket::http::{ContentType, Status}; + +#[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!"); +} -- cgit