-
-
Notifications
You must be signed in to change notification settings - Fork 158
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
BasicObjects do not have mocha ObjectMethods #589
Comments
Thanks for reporting this.
I think the simple answer to this is that when Mocha was first built, I know that in the past we've considered inheriting In the abstract it makes some sense to me that we leave If we were to change it, we'd need to think through the impact it might have on users of Mocha. My initial thought is that it would effectively be adding new functionality and so we wouldn't need to provide deprecation warnings and it could go out in a minor version bump. However, there are probably some obscure edge cases where the change might break some existing code if it was somehow relying on a class inheriting from I suppose another approach would be to make it a configuration option, but I'm less convinced about that. |
What do you think about providing these Mocha-related methods in a It seems like a reasonable compromise. You can get the behaviour if you need it, but you don't pollute the |
@floehopper sorry for the delay! I too have mixed feelings about this. In particular, no one has raised this before, and it's not blocking us - we only encountered it indirectly (the test still worked, albeit the expectation was defined on the underlying object instead of the delegator). I think the use case is pretty niche. Having it user-definable (e.g. via documenting a module to include in any object - can we reuse |
Thanks for the suggestion.
My slight concern with that approach is that the methods would probably end up being included twice in most objects/classes, i.e. once by default via A configuration option would be better, because we could decide to include into one or the other. If we go that way, I have a nagging feeling there might be some trickiness with the order of requiring files, but I haven't thought that through in any detail and I doubt it's insurmountable. |
No worries. Thanks for your thoughts. As explained above, I'm leaning towards making it a configuration option. I'll give it some more thought and maybe spike a solution when I've got some spare time. |
That would be totally ok actually. The dynamic dispatch of I think that works out much more simply than a configuration option, and it's a more standard/consistent mechanism that I would guess it's more lined up with user expectations. When faced with the question with "How do I get this method on this class?" I'm guessing most peoples first inclination is to look for the correct module, rather than some special-built configuration option. What do you think? |
I'm closing this in favour of #622. |
👋 hello! Came across the above, not sure if it's a bug or feature. An example:
The above fails with:
I'm curious if this is intentional - it seems to be because BasicObject isn't one of the patched classes:
mocha/lib/mocha/api.rb
Lines 39 to 42 in e32e9e5
How we came across this was pretty funny - we saw strict kwarg deprecation warnings for the
delegate.rb
module e.g.deprecation warning at /opt/rubies/3.1.2/lib/ruby/3.1.0/delegate.rb:87:in 'method_missing': Expectation defined at /opt/rubies/3.1.2/lib/ruby/3.1.0/delegate.rb:87:in 'method_missing' expected positional hash ({:a => 2}), but received keyword arguments (:a => 2). These will stop matching when strict keyword argument matching is enabled. See the documentation for Mocha::Configuration#strict_keyword_argument_matching=.
Turns out some tests were using SimpleDelegator, which inherits from BasicObject and thus doesn't have
.expect
. However, it attempts to passexpect
onto it's delegatee (?), which in our case inherited from Object and thus had the mocha object methods. Example to reproduce:The text was updated successfully, but these errors were encountered: