I’m writing some modules that I use to replace/extend the
functionality in a base class. I want to test these modules without
adding them to the original class.
My problem is that some of the module methods call #super to preserve
the base class’ functionality. However, in the spec there is no base
class and therefore no #super so I get a NoMethodError.
What is the proper way to check for the existence of a #super method
before invoking it?
What is the proper way to check for the existence of a #super method
before invoking it?
Hmm, how are you testing instance methods of a module without actually
mixing them into an object?
Maybe it would be easier just to have a fake superclass for testing,
with stubs for those methods. (Indeed, then you can test that super is
actually being called)
What is the proper way to check for the existence of a #super method before
invoking it?
defined? super
I believe OP rather wanted to test for existence of the same method in
the superclass. Although I have to say I am not 100% sure what he’s
after since the testing without instance seems strange.
An alternative would be to invoke it and rescue NoMethodError.
Another route would be to use instance_method but that might be
fragile.
I believe OP rather wanted to test for existence of the same method in
the superclass. Although I have to say I am not 100% sure what he’s
after since the testing without instance seems strange.
precisely what ‘defined?(super)’ does…
Amazing! Learn something new every day. Thanks, Ara, much appreciated.
Sorry for the noise, Pit.