[rspec-users] Is stubbing a call to super possible?

David Chelimsky dchelimsky at gmail.com
Mon May 25 01:04:26 EDT 2009

On Sun, May 24, 2009 at 2:25 PM, Fernando Perez <lists at ruby-forum.com> wrote:
>> In the meantime I have used alias_method_chain to override the method
>> in the super class.
> I up this old post, but I was having the same problem mocking super() so
> I had to alias_method_chain my method.

You can't mock super because super doesn't behave like other methods.
It is a language keyword that invokes the same method on the parent
class. So if you do this:

def foo

... the call to super calls foo on the superclass.

Since we don't get into the class hierarchy in rspec's mock/stub
framework, there is no facility for managing this. I believe that is
the case for mocha, flexmock and rr as well, though I could be wrong.


More information about the rspec-users mailing list