mirror of https://github.com/rwf2/Rocket.git
Add example for future testing API.
This commit is contained in:
parent
bb9faeb344
commit
99074a913d
|
@ -15,4 +15,5 @@ members = [
|
|||
"examples/todo",
|
||||
"examples/content_types",
|
||||
"examples/hello_ranks",
|
||||
"examples/testing",
|
||||
]
|
||||
|
|
|
@ -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" }
|
|
@ -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!")
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue