Forum: RSpec Can I set an expectation that a method invokes super?

Posted by Rick Denatale (rdenatale)
on 2010-01-28 18:57
(Received via mailing list)
Not sure if I can easily do this

Just ran into a bug in a rails app where ApplicationController
overrides rescue_action_in_public leading to the error page not being
displayed.

The fix was to call super at the end of the method.

I'd like to write a spec to ensure that this doesn't regress, but my
imagination is failing me as to how to do it.

Any ideas?

--
Rick DeNatale

Blog: http://talklikeaduck.denhaven2.com/
Twitter: http://twitter.com/RickDeNatale
WWR: http://www.workingwithrails.com/person/9021-rick-denatale
LinkedIn: http://www.linkedin.com/in/rickdenatale
Posted by Ashley Moran (Guest)
on 2010-01-28 20:17
(Received via mailing list)
On Jan 28, 2010, at 5:49 pm, Rick DeNatale wrote:

> I'd like to write a spec to ensure that this doesn't regress, but my
> imagination is failing me as to how to do it.
> 
> Any ideas?

Yes: don't use inheritance for implementations.  The bug you describe is 
arguably a violation of the Liskov Substitution Principle, ie the 
derived class changed the functionality it inherited in a way that broke 
the expected behaviour of all derived classes.

If you can write a spec (possibly shared examples) that defines the 
contract you expect *all* controllers to follow - eg display an error 
page in this situation - you can run that against all your controllers. 
Checking that you call `super` doesn't necessarily give you this 
security.

If you want to post #rescue_action_in_public there might be another way, 
depending on your code.  I'm no Rails guru though.

BTW if this sounds like a rant, it is :)  I am constantly stamping my 
feet over the way controllers in Rails, Merb etc are implemented, as 
they make writing specs extremely difficult.

Let me know if this is not clear as I've thrown the email together in a 
hurry before going home for the night...

Ashley

--
http://www.patchspace.co.uk/
http://www.linkedin.com/in/ashleymoran
Posted by Matt Patterson (Guest)
on 2010-01-30 10:57
(Received via mailing list)
On 28 Jan 2010, at 17:49, Rick DeNatale wrote:

> Not sure if I can easily do this
> 
> Just ran into a bug in a rails app where ApplicationController
> overrides rescue_action_in_public leading to the error page not being
> displayed.
> 
> The fix was to call super at the end of the method.
> 
> I'd like to write a spec to ensure that this doesn't regress, but my
> imagination is failing me as to how to do it.

Two thoughts, one not very helpful, the other hopefully more so.

My approach with this area has been to ignore the mechanics of error 
catching in controllers, to steer clear of rescue_action_in_public in 
apps - using rescue_from instead - and using a custom matcher to check 
that particular controllers declare that they rescue particular errors. 
To ensure that, in practice, the right stuff happens I use Cucumber to 
check that in a 404 type situation the right stuff happens across the 
whole stack.

HTH

Matt


--
  Matt Patterson | Design & Code
  <matt at reprocessed org> | http://www.reprocessed.org/
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.