I believe calls to super are sufficiently internal to the Ruby interpreter that a mocking framework can&#39;t intercept them without doing separate implementations for separate Ruby interpreters (and likely even separate versions).&nbsp; I could be wrong, but even so I&#39;d recommend a different approach.<br>
<br>If your need is really as simple as your example, what you have is just a method that has to get two things done: the base save and one additional call.&nbsp; You can write one (or more) example for each of those two things without your spec knowing that one of those things gets done by calling super.&nbsp; (You might object that by spec&#39;ing the base #save behavior you&#39;re spec&#39;ing the framework.&nbsp; I&#39;d say you&#39;re USING the framework to spec something your code does.&nbsp; To be clear, I&#39;m not suggesting you spec every detail of what save does: just something to make sure the record actually lands in the db.)<br>
<br>(Sidebar: Keep in mind the return value if you&#39;re really overriding #save like that.)<br><br>If you&#39;re dead set on spec&#39;ing that the super method gets called, there are a couple of hideous ways of doing it that will leak out of your example.&nbsp; Namely, you can (in your spec) redefine the method in the superclass and verify it gets called or (also in your spec, and this one&#39;s a little less leaky) have the class under test include a module that defines the same method and verify it gets called.&nbsp; Don&#39;t do either of those though (unless it&#39;s just to prove to yourself that they&#39;re possible).<br>
<br>-hume.<br><br><br><div class="gmail_quote">On Fri, May 2, 2008 at 5:17 PM, Matt McNeil &lt;<a href="mailto:nabble.108@xoxy.net">nabble.108@xoxy.net</a>&gt; wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br>
Hi there,<br>
<br>
How does one spec an invocation of a Ruby keyword, such as super in this<br>
case?<br>
<br>
class User &lt; ActiveResource::Base<br>
 &nbsp;# faking the ActiveRecord before/after_save observers<br>
 &nbsp;def save<br>
 &nbsp; &nbsp;super<br>
 &nbsp; &nbsp;UserMailer.deliver_activation(self) if recently_activated?<br>
 &nbsp;end<br>
end<br>
<br>
Does the solution look anything like the following?<br>
<br>
describe User do<br>
 &nbsp;describe &#39;#save&#39; do<br>
 &nbsp; &nbsp;it &quot;should call save on the parent class&quot; do<br>
 &nbsp; &nbsp; &nbsp;# something.should_receive(:something)<br>
 &nbsp; &nbsp; &nbsp;@user.save<br>
 &nbsp; &nbsp;end<br>
 &nbsp;end<br>
end<br>
<br>
Any thoughts?<br>
<br>
Thanks much,<br>
Matt<br>
<font color="#888888"><br>
--<br>
View this message in context: <a href="http://www.nabble.com/spec%27ing-calls-to-super-%28or-other-Ruby-keywords%29-tp17027929p17027929.html" target="_blank">http://www.nabble.com/spec%27ing-calls-to-super-%28or-other-Ruby-keywords%29-tp17027929p17027929.html</a><br>

Sent from the rspec-users mailing list archive at Nabble.com.<br>
<br>
_______________________________________________<br>
rspec-users mailing list<br>
<a href="mailto:rspec-users@rubyforge.org">rspec-users@rubyforge.org</a><br>
<a href="http://rubyforge.org/mailman/listinfo/rspec-users" target="_blank">http://rubyforge.org/mailman/listinfo/rspec-users</a><br>
</font></blockquote></div><br>