Shane Mingins
2008-Nov-18 08:44 UTC
[rspec-users] Spec''ing specific before_filters in controllers
Hi I like using before_filter in controllers to dry up code. From what I have read I understand that this is not something everyone agrees upon. Never mind. I was looking for a way in my controller spec''s to basically 1. assert that I have applied the before_filter on the actions I want and 2. execute the before_filter if it is defined in that controller and assert that it is doing as it should. To me that seems to be the specific behaviour I am after. I really only wanted to do this in one place ... and not have to "share" it anywhere. Also I wanted to do a little more than some of the solutions I found. Anyways ... I ended up with a spec description like this: http://pastie.org/317459 And then in the rest of the spec I can stub the before_filter methods like here http://www.caboo.se/articles/2007/8/24/skinny-controllers-skinnier-controller-specs So just wondered any thoughts ... have you seen anything else around? The code behind it at the moment is quite trivial and will probably grow if I have other filter types. I can post a better write up if this sounds like something useful for others. There is this matcher: http://github.com/ngty/have_filter/tree/ master .... but again, it wasn''t quite what I felt I wanted. Cheers Shane -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20081118/5ec8bd8b/attachment.html> -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/pkcs7-signature Size: 2423 bytes Desc: not available URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20081118/5ec8bd8b/attachment.bin>