-
Notifications
You must be signed in to change notification settings - Fork 644
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Provide a better error message when mocking fails and improve ergonomics #425
base: master
Are you sure you want to change the base?
Provide a better error message when mocking fails and improve ergonomics #425
Conversation
As a note, I couldn't quite get the
Is there any way to get the panic message back so we can |
* Removed the Unpin requirement on Response::fut() * Updated the change log Co-authored-by: Michael Bryan <mbryan@autronics.com.au> Co-authored-by: Yuki Okushi <huyuumi.dev@gmail.com>
The current one causes failure.
Co-authored-by: Jonathas Conceição <jadoliveira@inf.ufpel.edu.br> Co-authored-by: Rob Ede <robjtede@icloud.com>
Co-authored-by: Yuki Okushi <huyuumi.dev@gmail.com>
Co-authored-by: Rob Ede <robjtede@icloud.com>
Co-authored-by: Rob Ede <robjtede@icloud.com> Co-authored-by: Yuki Okushi <huyuumi.dev@gmail.com>
* fix system start examples with break change of actix-rt * update changelog * fix test_macro * remove actix-rt override
Co-authored-by: Rob Ede <robjtede@icloud.com>
* fixed futures_util deprecation warnings * Update CHANGES.md Co-authored-by: Rob Ede <robjtede@icloud.com>
* Update futures-util dependency * Update CHANGES.md * Update Cargo.toml Co-authored-by: Rob Ede <robjtede@icloud.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Rob Ede <robjtede@icloud.com>
Updates the requirements on [ahash](https://github.com/tkaitchuck/ahash) to permit the latest version. - [Release notes](https://github.com/tkaitchuck/ahash/releases) - [Commits](tkaitchuck/aHash@v0.7.6...v0.8.3) --- updated-dependencies: - dependency-name: ahash dependency-type: direct:production ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Rob Ede <robjtede@icloud.com>
* Update bitflags requirement from 1.2 to 2.3 Updates the requirements on [bitflags](https://github.com/bitflags/bitflags) to permit the latest version. - [Release notes](https://github.com/bitflags/bitflags/releases) - [Changelog](https://github.com/bitflags/bitflags/blob/main/CHANGELOG.md) - [Commits](bitflags/bitflags@1.2.0...2.3.3) --- updated-dependencies: - dependency-name: bitflags dependency-type: direct:production ... Signed-off-by: dependabot[bot] <support@github.com> * fix bitflags update * loosen bitflags requirement --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Rob Ede <robjtede@icloud.com>
* Update actix-web requirement from 3 to 4 Updates the requirements on [actix-web](https://github.com/actix/actix-web) to permit the latest version. - [Release notes](https://github.com/actix/actix-web/releases) - [Changelog](https://github.com/actix/actix-web/blob/master/CHANGES.md) - [Commits](actix/actix-web@awc-v3.0.0...web-v4.3.1) --- updated-dependencies: - dependency-name: actix-web dependency-type: direct:production ... Signed-off-by: dependabot[bot] <support@github.com> * chore: include default actix-web features --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Rob Ede <robjtede@icloud.com>
Co-authored-by: Rob Ede <robjtede@icloud.com>
Co-authored-by: Rob Ede <robjtede@icloud.com>
Marking as draft due to CI failures. LMK if you're still interested in pursuing this PR. |
PR Type
Refactor. Optionally with some additional functionality.
PR Checklist
Check your PR fulfills the following:
Overview
The
Mocker
type passes aroundBox<dyn Any>
for both messages and message results. That means it's not uncommon for yourmock
function to accidentally return the wrong type and panic with a rather cryptic"wrong return type for message"
.The main feature of this PR is to adjust the panic message to mention the type
M: Message
theMocker<T>
is handling, and the typeM::Result
we expected themock
function to return.As an addition (which can be cherry picked out if we don't want to include it), the implementation of
Handler<M>
required that instead of returning aM::Result
directly, themock
function returns aOption<M::Result>
so we can dodowncast_mut()
and amem::replace()
to extract theM::Result
. 69f4135 switches to usingret.downcast::<M::Result>()
instead ofdowncast_mut()
so we can take theM::Result
by value, chaining on aret.downcast::<Option<M::Result>>()
so we retain the original behaviour.A second optional addition, 5d47d1f, adds a
Mocker::mock_one()
constructor for when yourMocker
will only need to mock a single message. This lets the user avoid writing code for manually boxing and downcasting.This change introduces the use of
std::any::type_name()
which only became stable in Rust 1.38.0. The MSRV for Actix is 1.40, so this PR shouldn't introduce any backwards compatibility issues.