Add example for future testing API.

This commit is contained in:
Sergio Benitez 2016-08-27 16:20:01 -07:00
parent bb9faeb344
commit 99074a913d
3 changed files with 45 additions and 0 deletions

View File

@ -15,4 +15,5 @@ members = [
"examples/todo",
"examples/content_types",
"examples/hello_ranks",
"examples/testing",
]

View File

@ -0,0 +1,9 @@
[package]
name = "testing"
version = "0.0.1"
authors = ["Sergio Benitez <sb@sergio.bz>"]
workspace = "../../"
[dependencies]
rocket = { path = "../../lib" }
rocket_macros = { path = "../../macros" }

View File

@ -0,0 +1,35 @@
#![feature(plugin)]
#![plugin(rocket_macros)]
extern crate rocket;
use rocket::Rocket;
#[GET(path = "/")]
fn hello() -> &'static str {
"Hello, world!"
}
fn main() {
Rocket::new("localhost", 8000).mount_and_launch("/", routes![hello]);
}
#[cfg(test)]
mod test {
use super::rocket::{Rocket, Request, Method};
fn run_test<F>(f: F) where F: Fn(Rocket) {
let mut rocket = Rocket::new("_", 0);
rocket.mount("/", routes![super::hello]);
f(rocket);
}
#[test]
fn test_hello() {
run_test(|_rocket: Rocket| {
let _req = Request::mock(Method::Get, "/");
// TODO: Allow something like this:
// let result = rocket.route(&req);
// assert_eq!(result.as_str(), "Hello, world!")
});
}
}