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
Fixing an issue with a spoiling of the object singleton classes #891
base: master
Are you sure you want to change the base?
Conversation
…initions. This could lead to real issues with the global objects like classes, class variables e.t.c.
…stubbing class method, then it's defined on the class singleton_class, and should be kept.
* new module with assertion methods added * assert_method_called added, this is a flow assertion, you can check the params, and you can check that method was called inside the block, without stubbing objects and interfering with the original flow * minimal ruby version set to 2.5 ( so we can replace indirect invocations via send(:*_method ) to direct invocations ) * singleton_classes is now properly cleared after, see PR: minitest/minitest#891 * some methods got '__' prefixes, just to prevent naming collisions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about when you're stubbing a singleton class method instead of an instance method? This would erase the method on the singleton class, unless I'm reading it wrong.
Also consider these other cases: #811 |
hm, what about the testcase in the PR:
Looks like its covering your concern |
.stub method defined in minitest/mock executing an alias_method against singleton_class under the hood.
Running an alias_method over a singleton_class without running a 'remove_method' later will keep singleton_class 'dirty' and running undef_method might clear more than needed.
Usually this will not lead to any consequences, but if you are stubbing methods of a global objects and trying to enrich functionality of their ancestors chain 'after' the the first stubbing is done, then you might fall into trouble.
Even though the probability for such a case is tiny, it's not 0 and singleton class should be kept clean.