I need to write some wrapper classes, that derive from SWIG generated
proxy classes for some C/C++ extensions.
The Ruby wrapper classes need to do a lot of ‘super’ calls to the base
classes generated by SWIG.
The question is: Is there any way to make RSpec mock a base class and
record/verify that certain methods on a base class are called?
As long as the methods in the derived class have different names this is
no problem, but otherwise it doesn’t seem to be possible - at least not
with RSpec’s mocking/stubbing facilities, does it?
I see other ways to do this, like wrapping an instance of the Swig class
instead of deriving from it or writing some custom mocking code that
the base class e.g. with define_method, but I’m especially asking if
is possible with RSpec.
def do_something(arg) end
class Derived << Swig::Base
yield(self) if block_given?
def do_something(arg) do_something(arg) # additional behaviour here end
describe Wrapper::Derived do
it ‘should initialize the base class with the same argument’ do
# No idea, how to mock Base.initialize() here
it ‘should do something with the base class when doing something’ do
# No idea, how to mock Base.do_something() here