Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
add stub_any_instance method #245
referenced this pull request
Sep 22, 2013
Just out of curiosity @zenspider , what is the reason for not having this in the core?
I understand that we can't put everything in core but I would find it more useful to have this method instead of some shortcuts like
This is not a rant by the way, I am pretty sure there is a reason, like a downside or something and I'd like to know what it is.
@zenspider, yes I know there is a plugin, I use it sometimes.
Believe it or not, I am hoping to learn something from you.
I'd like to know if you would use this plugin for your own test or not for example.
Or maybe you think it is not necessarily a good way to test in the first place, and that would interest me as well.
The thing is that minitest is very simple to understand indeed and at the end of the day, knowing what to test and how to test it is a much harder task, at least for me. I realised that people (including me) often end up wanting more features because they don't necessarily use their tool in the best way possible.
This is the reason why I try to read the tests of minitest itself a lot.
Could you please give me your insight on this subject?
It's not a move, because it was never added.
Personally, I never use mocks and I almost never use stubs (and when I do, it's most often via
I share @zenspider's opinion that
Even if you do use mocks, you should be able to inject a mock and control what's happening.
There are some edge cases where
define_method(name) do |*args| if val_or_callable.respond_to? :call then instance_exec(*args, &val_or_callable) else val_or_callable end end
It breaks because the mocked method responds to
I find the balance between testing only one thing at a time and not testing the implementation very hard. I probably would trade any testing framework for a good book which contains the truth about testing. Only half joking here, but this is why I value the code maintainers' vision as much as the code itself.
Anyway, sorry for keeping this outdated thread alive. Thank you guys for taking the time to answer my questions.