diff --git a/src/lib.rs b/src/lib.rs index c0169d0..69c3c57 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -93,6 +93,8 @@ impl ::std::fmt::Display for Error { /// `rustc_serialize::Encodable`, and the result type must implement `rustc_serialize::Decodable`. /// This can usually be achieved with `#[derive(RustcEncodable)]` and `#[derive(RustcDecodable)]`. /// +/// **Note:** If not providing data, you must provide a parameterized `None` such as `None::`. +/// /// # Example /// /// ```no_run diff --git a/tests/lib.rs b/tests/lib.rs index 280df2c..220cef4 100644 --- a/tests/lib.rs +++ b/tests/lib.rs @@ -38,21 +38,23 @@ struct ResponseData { pong: bool } -const HOST: &'static str = "0.0.0.0:12345"; -fn url(frag: &str) -> String { - format!("http://{}{}", HOST, frag) -} - struct StackListener { - server: ::hyper::server::Listening + server: ::hyper::server::Listening, + host: String, } impl StackListener { - pub fn new() -> StackListener { + pub fn new(port: u16) -> StackListener { + let host = format!("0.0.0.0:{}", port); StackListener { - server: PingServer::build().listen_with(HOST, 1, Protocol::Http).unwrap() + server: PingServer::build().listen_with(&host[..], 1, Protocol::Http).unwrap(), + host: host } } + + pub fn url(&self, path: &str) -> String { + format!("http://{}{}", self.host, path) + } } impl Drop for StackListener { @@ -63,22 +65,22 @@ impl Drop for StackListener { #[test] #[allow(unused_variables)] -fn ping_pong() { - let server = StackListener::new(); +fn with_data() { + let server = StackListener::new(40918); let req = RequestData { ping: true }; // When this fails, the error I get it "called Option::unwrap() on a None value" which is not // helpful for resolving what the problem is. - let res: ResponseData = request(Method::Post, &(url("/ping"))[..], Some(req)).unwrap().unwrap(); + let url = server.url("/ping"); + let res: ResponseData = request(Method::Post, &url[..], Some(req)).unwrap().unwrap(); } #[test] #[allow(unused_variables)] -fn ping_pong_none_data() { - let server = StackListener::new(); +fn none_data() { + let server = StackListener::new(40919); - // When this fails, the error I get it "called Option::unwrap() on a None value" which is not - // helpful for resolving what the problem is. - let res: ResponseData = request(Method::Post, &(url("/ping"))[..], None).unwrap().unwrap(); + let url = server.url("/ping"); + let res: ResponseData = request(Method::Post, &url[..], None::).unwrap().unwrap(); }