<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On May 3, 2008, at 11:09 AM, Al Chou wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0; "><div><div style="font-family: verdana, helvetica, sans-serif; font-size: 10pt; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">In the particular case of super, another approach, though perhaps not using the spec framework, would be to assert (a la Test::Unit) that your class is a subclass of the intended superclass.&nbsp; To be truly anal, also assert that the superclass has a method with the same name as the subclass's method of interest and that the subclass has that method, too.&nbsp; But all this seems deeply into the xUnit world, and far from the BDD way.<br><br>Al</div></div></span></blockquote><div><br></div><div>The truth is that you shouldn't be spec'ing calls to the super "method", but rather the behaviour of super. &nbsp;One quick way to do this is as so:</div><div><br></div><div>[BaseClass, Subclass].each { |klass|</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>it "should do whatever super does" do<br></div><div><span class="Apple-tab-span" style="white-space:pre">                </span>klass.new.foo_bar.should == :baz<br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>end</div><div>end</div><div><br></div><div>Your original example is a little trickier, because you didn't write the base class, and you probably aren't going to spec it out. &nbsp;There's obviously great complexity in that call to super. &nbsp;Now you know why none of us like writing specs against rails apps.</div><div><br></div><div>Scott</div><div><br></div><br><blockquote type="cite"><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0; "><div><div style="font-family: verdana, helvetica, sans-serif; font-size: 10pt; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><div style="font-family: verdana, helvetica, sans-serif; font-size: 10pt; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><br><br><div style="font-family: 'times new roman', 'new york', times, serif; font-size: 12pt; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">----- Original Message ----<br>From: John D. Hume &lt;<a href="mailto:duelin.markers@gmail.com">duelin.markers@gmail.com</a>><br>To: rspec-users &lt;<a href="mailto:rspec-users@rubyforge.org">rspec-users@rubyforge.org</a>><br>Sent: Saturday, May 3, 2008 7:49:11 AM<br>Subject: Re: [rspec-users] spec'ing calls to super (or other Ruby keywords)<br><br>I believe calls to super are sufficiently internal to the Ruby interpreter that a mocking framework can'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'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'ing the base #save behavior you're spec'ing the framework.&nbsp; I'd say you're USING the framework to spec something your code does.&nbsp; To be clear, I'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're really overriding #save like that.)<br><br>If you're dead set on spec'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'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't do either of those though (unless it's just to prove to yourself that they're possible).<br><br>-hume.<br><br><br><div class="gmail_quote" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">On Fri, May 2, 2008 at 5:17 PM, Matt McNeil &lt;<a rel="nofollow" ymailto="mailto:nabble.108@xoxy.net" target="_blank" href="mailto:nabble.108@xoxy.net">nabble.108@xoxy.net</a>> wrote:<br><blockquote class="gmail_quote" style="border-left-width: 1px; border-left-style: solid; border-left-color: rgb(204, 204, 204); margin-top: 0pt; margin-right: 0pt; margin-bottom: 0pt; margin-left: 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 '#save' do<br>&nbsp; &nbsp;it "should call save on the parent class" 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</blockquote></div></div></div></div></div><br><hr size="1">Be a better friend, newshound, and know-it-all with Yahoo! Mobile.<span class="Apple-converted-space">&nbsp;</span><a href="http://us.rd.yahoo.com/evt=51733/*http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ ">Try it now.</a>_______________________________________________<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">http://rubyforge.org/mailman/listinfo/rspec-users</a></div></span></blockquote></div><br></body></html>