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

318 views
Skip to first unread message

Fernando Perez

unread,
May 24, 2009, 2:25:53 PM5/24/09
to rspec...@rubyforge.org
> 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.
--
Posted via http://www.ruby-forum.com/.
_______________________________________________
rspec-users mailing list
rspec...@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users

David Chelimsky

unread,
May 25, 2009, 1:04:26 AM5/25/09
to rspec...@rubyforge.org
On Sun, May 24, 2009 at 2:25 PM, Fernando Perez <li...@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
super
end

... 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.

HTH,
David

Reply all
Reply to author
Forward
0 new messages