Skip to content

Instantly share code, notes, and snippets.

@felipesere
Created March 19, 2017 12:20
Show Gist options
  • Save felipesere/c9adfdaacfe19f97ae4ad9044c01231a to your computer and use it in GitHub Desktop.
Save felipesere/c9adfdaacfe19f97ae4ad9044c01231a to your computer and use it in GitHub Desktop.
lazy_static! {
pub static ref ROCKET: rocket::Rocket = {
println!("Creating a rocket");
super::build_rocket("postgres://advisor_test@localhost/advisor_test")
};
}
#[test]
fn through_the_rocket_infrastructure() {
let mut req = MockRequest::new(Method::Get, "/");
let mut response = req.dispatch_with(&ROCKET);
assert_eq!(response.status(), Status::Ok);
let body_str = response.body().and_then(|b| b.into_string()).unwrap();
assert_eq!(node_text(body_str, "h1"), vec!["Advisor".to_owned()]);
}
fn node_text(body: String, selector: &'static str) -> Vec<String> {
let document = kuchiki::parse_html().one(body);
let mut matches = Vec::new();
for node in document.select(selector).unwrap() {
let as_node = node.as_node();
let text_node = as_node.first_child().unwrap();
let text = text_node.as_text().unwrap().borrow();
matches.push(text.to_owned());
}
matches
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment