mirror of
https://github.com/askama-rs/askama.git
synced 2025-10-02 15:25:19 +00:00
Add test for Rocket support
This commit is contained in:
parent
bf51e7264f
commit
e030066106
@ -5,10 +5,16 @@ authors = ["Dirkjan Ochtman <dirkjan@ochtman.nl>"]
|
|||||||
workspace = ".."
|
workspace = ".."
|
||||||
build = "build.rs"
|
build = "build.rs"
|
||||||
|
|
||||||
|
[features]
|
||||||
|
default = []
|
||||||
|
nightly = ["rocket", "rocket_codegen", "askama/with-rocket"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
iron = "0.5"
|
iron = "0.5"
|
||||||
serde_json = "1.0"
|
serde_json = "1.0"
|
||||||
askama = { path = "../askama", version = "*", features = ["with-iron", "serde-json"] }
|
askama = { path = "../askama", version = "*", features = ["with-iron", "serde-json"] }
|
||||||
|
rocket = { version = "0.3", optional = true }
|
||||||
|
rocket_codegen = { version = "0.3", optional = true }
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
askama = { path = "../askama", version = "*", features = ["with-iron", "serde-json"] }
|
askama = { path = "../askama", version = "*", features = ["with-iron", "serde-json"] }
|
||||||
|
33
testing/tests/rocket.rs
Normal file
33
testing/tests/rocket.rs
Normal file
@ -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!");
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user