alexliesenfeld / httpmock

HTTP mocking library for Rust.
MIT License
436 stars 40 forks source link

Fixed debugger issues in body_from_path for absolute paths #24

Closed UebelAndre closed 3 years ago

UebelAndre commented 3 years ago

I decided to remake #18 which would solve my concerns for #17

UebelAndre commented 3 years ago

I think you're gonna want to update the documentation a little based on this change.

on crates.io it shows

// Create a mock on the server.
let hello_mock = server.mock(|when, then| {
    when.method(GET)
        .path("/translate")
        .query_param("word", "hello");
    then.status(200)
        .header("Content-Type", "text/html; charset=UTF-8")
        .body("Привет");
});

/translate is actually an absolute path. It should be updated to translate or ./translate

alexliesenfeld commented 3 years ago

Do you mean the path method? If yes, it's the URL path, not a file path (like in http://localhost:8080/myPath)

UebelAndre commented 3 years ago

aaaah, my bad. As you were 😅

Thanks again!! 🙏

UebelAndre commented 3 years ago

This is where I first tried the library, yeah. I had read it but I thought I also read when MockServer is dropped it asserts that all the mocks had been called. Right?

On Sat, Oct 24, 2020 at 6:11 PM, Alexander Liesenfeld notifications@github.com wrote:

Now that you show the example, I took the time and watched through cargo-raze (I guess you use httpmock for it?). Did you know about httpmocks assert feature?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.

alexliesenfeld commented 3 years ago

This is where I first tried the library, yeah. I had read it but I thought I also read when MockServer is dropped it asserts that all the mocks had been called. Right? On Sat, Oct 24, 2020 at 6:11 PM, Alexander Liesenfeld @.***> wrote: Now that you show the example, I took the time and watched through cargo-raze (I guess you use httpmock for it?). Did you know about httpmocks assert feature? — You are receiving this because you authored the thread. Reply to this email directly, [view it on GitHub](#24 (comment)), or unsubscribe.

No! I know thare are some other Rust libraries that do this (such as httptest) but I don't think it's very useful. The reason is because your code will almost always fail first before any assertions are done by the mock library at drop time. Ideally, just call mock.assert() before your other assertions then you know for sure your client made the expected calls. The examples in the docs demonstrate this (or just look here).