Skip to content
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

Feature Request: Mock object IDs #524

Open
chanq-io opened this issue Nov 28, 2023 · 2 comments
Open

Feature Request: Mock object IDs #524

chanq-io opened this issue Nov 28, 2023 · 2 comments
Labels
enhancement New feature or request

Comments

@chanq-io
Copy link

Hello!

Firstly, respect due on this amazing crate. Has made testing a dream for projects I've been working on.

I was wondering if there would be anyway to construct Mocks with some kind of identifier? Or the some way to add contextual information to expectations? I realise anything with a member variables is typically un-mock-like, but for larger integration tests with tons of mocks flying around I often am left scratching my head when something falls over. For example, say I have 20-30 MockThing instances wrapped in MyContainer which performs a series of operations on them by calling .foo(x, y) and each MockThing::foo has custom expectations defined on it... When one of those expectations fails, I get a panic like:

thread 'tests::my_container' panicked at 'MockThing::foo(?, ?): No matching expectation found'

Which is a pain to diagnose.. But, if we had some contextual information added to the Mock or Expectation, then it would make it much easier to fix.

Thanks

@asomers asomers added the enhancement New feature or request label Nov 28, 2023
@asomers
Copy link
Owner

asomers commented Nov 28, 2023

I'm glad you like it! As for your question, one thing immediately comes to mind: you'll get better error messages if you enable the nightly crate feature. As its name suggests, that requires a nightly compiler. Or, if you use the latest unreleased crate from the git master branch, you'll also get better error messages even without the nightly feature.

As for some kind of mock id, I can see how that would be useful for your case. Other than panic messages, are there any other places where you think it might be helpful?

@chanq-io
Copy link
Author

Thanks for the quick response.

nightly is only an option for my personal projects unfortunately, work requirements are stricter. But, good to know I can pull tip of main to get better error messages.

In addition to improved panics, it could be useful to have a derived Display implementation that output this user defined contextual info so you could print whole test objects prior to running whatever logic causes a panic

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants