diff --git a/Cargo.toml b/Cargo.toml index 5de0ac08..d567a94e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,4 +15,5 @@ members = [ "examples/todo", "examples/content_types", "examples/hello_ranks", + "examples/testing", ] diff --git a/examples/testing/Cargo.toml b/examples/testing/Cargo.toml new file mode 100644 index 00000000..33efcfc9 --- /dev/null +++ b/examples/testing/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "testing" +version = "0.0.1" +authors = ["Sergio Benitez "] +workspace = "../../" + +[dependencies] +rocket = { path = "../../lib" } +rocket_macros = { path = "../../macros" } diff --git a/examples/testing/src/main.rs b/examples/testing/src/main.rs new file mode 100644 index 00000000..beb8e218 --- /dev/null +++ b/examples/testing/src/main.rs @@ -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) 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!") + }); + } +}