Skip to content

Commit

Permalink
Add query to Request Display impl and print it in last unmatched requ…
Browse files Browse the repository at this point in the history
…est diffs
  • Loading branch information
lipanski committed Mar 31, 2023
1 parent 1276b06 commit 2e140c2
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
31 changes: 31 additions & 0 deletions tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 2e140c2

Please sign in to comment.