Created
March 19, 2017 12:20
-
-
Save felipesere/c9adfdaacfe19f97ae4ad9044c01231a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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