-
Notifications
You must be signed in to change notification settings - Fork 302
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Mocking doesn't work with objects other than Excel.Application #6246
Comments
Yeah I kind of got a little too excited there, this was always going to be highly experimental stuff 😅 Honestly I fixed some merge conflicts and fixed a unit test or two; the branch had been collecting dust for a long time and I should probably have tested it a bit more, uh, deeply. This PR simply had to be merged, but yeah if it survives pre-release it'll probably release as an experimental feature. I was preparing a blog article about the feature and toying with it a bit more ...and yikes, indeed it's much more limited than I thought (although I'm sure @bclothier told me many times). I'm going to continue to play with it to try and see whether there's one realistic use case that works (no luck so far), and I'm sure there's several ways to enhance the API to add whatever is missing to make it work. FWIW I was able to get a mock worksheet with Other than these technicalities, I'm finding that the sheer amount of methods and properties that yield a |
You got excited? When I read the blog post, I nearly spurted coffee out my nose and fell out of my chair. 🙂 Mocking would be an absolute game-changer for VBA development. I follow good OO design and organize code into many small collaborating classes, and try to abstract most of them away from dealing directly with Anyway, please keep up the great work. I just started using Rubberduck yesterday and it's an amazingly helpful add-in. I can never again go back to the plain vanilla VBA Editor. |
Indeed! In fact I was ambitiously hoping for it to make stubs entirely redundant. I've yet to try mocking user code (VBA classes); I'm aware of some serious limitations with it, but if it works at all it's still a massive game changer, especially in a project that has stable interfaces. I'll include my findings in the upcoming blog post.
Oh wow, you're in for a ride! Make sure you check out
We can never read this kind of feedback too many times, thank you so much! |
Agreed, that would be great as well. I think I tried mocking one of my user classes, and also got an error. I think it was the same one I got for the
Yes, I love the folders. Truth be told, I already had a similar workaround. I'm from Java land, so used to having packages. So I prefix all my class names with a package prefix that's an acronym of the actual package. E.g. a
You're most welcome! I know how much work something like Rubberduck must take, and truly appreciate all the time and effort you guys have all put in. I'm sure there are many other users who feel the same. |
Another idea... If mocking real Excel or user classes doesn't work, but there's a way to mock just a general class like Although I guess that wouldn't be a great solution, as then you lose the type safety of passing the mocked object around to procedures that expect its actual type. |
Rubberduck version information
Description
I was able to successfully use the mocking example of
Excel.Application
described in the Quick Start here:https://github.com/rubberduck-vba/Rubberduck/wiki/VBA-Moq-Mocking-Framework#quick-start
But as soon as I tried mocking a different Excel object, like
Excel.Range
,Excel.Font
,Excel.Interior
, I got the following error when executing e.g.Mocks.Mock("Excel.Range")
:Same error for
Excel.Font
andExcel.Interior
.Can any Excel objects other than
Excel.Application
be currently mocked?To Reproduce
Steps to reproduce the behavior:
Dim Mock As Rubberduck.ComMock: Set Mock = Mocks.Mock("Excel.Range")
Expected behavior
I'm expecting to be able to mock most Excel objects, not just
Excel.Application
.Screenshots
Logfile
Additional context
The text was updated successfully, but these errors were encountered: