diff --git a/src/request.rs b/src/request.rs index a12d94c..fd0d766 100644 --- a/src/request.rs +++ b/src/request.rs @@ -82,7 +82,12 @@ impl Request { let mut formatted = format!( "\r\n{} {}\r\n", &self.inner.method(), - &self.inner.uri().path() + &self + .inner + .uri() + .path_and_query() + .map(|pq| pq.as_str()) + .unwrap_or("") ); for (key, value) in self.inner.headers() { diff --git a/tests/lib.rs b/tests/lib.rs index 6bc0fe1..d22c3c6 100644 --- a/tests/lib.rs +++ b/tests/lib.rs @@ -1399,6 +1399,37 @@ fn test_assert_with_last_unmatched_request() { mock.assert(); } +#[test] +#[should_panic( + expected = "\n> Expected 1 request(s) to:\n\r\nGET /hello?world=1\r\n\n...but received 0\n\n> The last unmatched request was:\n\r\nGET /hello?world=2\r\n\n> Difference:\n\n\u{1b}[31mGET /hello?world=1\n\u{1b}[0m\u{1b}[32mGET\u{1b}[0m\u{1b}[32m \u{1b}[0m\u{1b}[42;30m/hello?world=2\u{1b}[0m\u{1b}[32m\n\u{1b}[0m\n\n" +)] +#[cfg(feature = "color")] +fn test_assert_with_last_unmatched_request_and_query() { + let mut s = Server::new(); + let host = s.host_with_port(); + let mock = s.mock("GET", "/hello?world=1").create(); + + request(&host, "GET /hello?world=2", ""); + + mock.assert(); +} + +// Same test but without colors (for Appveyor) +#[test] +#[should_panic( + expected = "\n> Expected 1 request(s) to:\n\r\nGET /hello?world=1\r\n\n...but received 0\n\n> The last unmatched request was:\n\r\nGET /hello?world=2\r\n\n> Difference:\n\nGET /hello?world=1\nGET /hello?world=2\n\n\n" +)] +#[cfg(not(feature = "color"))] +fn test_assert_with_last_unmatched_request_and_query() { + let mut s = Server::new(); + let host = s.host_with_port(); + let mock = s.mock("GET", "/hello?world=1").create(); + + request(&host, "GET /hello?world=2", ""); + + mock.assert(); +} + #[test] #[should_panic( expected = "\n> Expected 1 request(s) to:\n\r\nGET /hello\r\n\n...but received 0\n\n> The last unmatched request was:\n\r\nGET /bye\r\nauthorization: 1234\r\naccept: text\r\n\n> Difference:\n\n\u{1b}[31mGET /hello\n\u{1b}[0m\u{1b}[32mGET\u{1b}[0m\u{1b}[32m \u{1b}[0m\u{1b}[42;30m/bye\u{1b}[0m\u{1b}[32m\n\u{1b}[0m\u{1b}[92mauthorization: 1234\n\u{1b}[0m\u{1b}[92maccept: text\n\u{1b}[0m\n\n"