Rocket/examples/testing/src/main.rs

31 lines
685 B
Rust
Raw Normal View History

2016-08-27 23:20:01 +00:00
#![feature(plugin)]
2016-09-09 03:38:58 +00:00
#![plugin(rocket_codegen)]
2016-08-27 23:20:01 +00:00
extern crate rocket;
2016-09-04 11:06:28 +00:00
#[get("/")]
2016-08-27 23:20:01 +00:00
fn hello() -> &'static str {
"Hello, world!"
}
fn main() {
rocket::ignite().mount("/", routes![hello]).launch()
2016-08-27 23:20:01 +00:00
}
#[cfg(test)]
mod test {
use super::rocket;
use rocket::testing::MockRequest;
use rocket::http::Method::*;
2016-08-27 23:20:01 +00:00
#[test]
fn test_hello() {
let rocket = rocket::ignite().mount("/", routes![super::hello]);
let mut req = MockRequest::new(Get, "/");
let mut response = req.dispatch_with(&rocket);
let body_string = response.body().and_then(|b| b.to_string());
assert_eq!(body_string, Some("Hello, world!".to_string()));
2016-08-27 23:20:01 +00:00
}
}